The Permaweb Cookbook is a developer resource that provides the essential concepts and references for buiding applications on the Permaweb. Each concept and reference will focus on specific aspects of the Permaweb development ecosystem while providing additional details and usage examples.Permaweb Cookbook 是一种开发人员资源,它提供了在 Permaweb 上构建应用程序的基本概念和参考。每个概念和参考资料都将侧重于 Permaweb 开发生态系统的特定方面,同时提供额外的细节和使用示例。
Welcome to the Arweave development community, where the past is forever etched in the blockchain and the future is full of endless possibilities. Let's build the decentralized web together!欢迎来到 Arweave 开发社区,过去永远铭刻在区块链中,未来充满无限可能。让我们一起构建去中心化网络!
The Cookbook is designed in a way that makes it easy for new Permaweb developers to contribute. Even if you don't know how to do something, contributing to the cookbook is a great way to learn!Cookbook 的设计方式使新的 Permaweb 开发人员可以轻松做出贡献。即使您不知道如何做某事,为食谱做贡献也是一种很好的学习方式!
Check out all open issues here. Contribution guidelines here. if you find the cookbook is missing a concept, guide or reference, please add an issue.在此处查看所有未解决的问题。贡献指南在这里。如果您发现食谱缺少概念、指南或参考,请添加问题。
Creating applications on the permaweb, which is built on the Arweave protocol, is similar to building traditional web applications but with some key differences.在基于 Arweave 协议构建的 permaweb 上创建应用程序类似于构建传统的 Web 应用程序,但有一些关键区别。
One major difference is that data is stored on the permaweb permanently, as the name suggests, rather than on a centralized server. This means that once data is uploaded to the permaweb, it cannot be deleted or altered. This can be beneficial for applications that require tamper-proof data storage, such as supply chain management or voting systems.一个主要区别是,顾名思义,数据永久存储在 permaweb 上,而不是存储在中央服务器上。这意味着一旦数据上传到 permaweb,就无法删除或更改。这对于需要防篡改数据存储的应用程序可能是有益的,例如供应链管理或投票系统。
Another difference is that the permaweb is decentralized, meaning there is no central point of control or failure. This can provide increased security and reliability for applications.另一个区别是 permaweb 是分散的,这意味着没有中央控制点或故障点。这可以为应用程序提供更高的安全性和可靠性。
Additionally, the permaweb uses a unique token, called AR, to pay for the storage of data on the network. This can add a new layer of complexity to application development, as developers need to consider how to integrate AR into their applications and handle payments.此外,permaweb 使用一种称为 AR 的独特令牌来支付网络上数据的存储费用。这会给应用程序开发增加一层新的复杂性,因为开发人员需要考虑如何将 AR 集成到他们的应用程序中并处理支付。
Overall, the experience of creating applications on the permaweb can be challenging, but it can also be rewarding as it offers unique benefits over traditional web development.总的来说,在 permaweb 上创建应用程序的体验可能具有挑战性,但它也可能是有益的,因为它提供了优于传统 Web 开发的独特优势。
Go to the arweave faucet and generate a wallet with AR, this requires a twitter account. You will be prompted to download your keyfile as file.json.转到arweave水龙头并生成带有AR的钱包,这需要一个twitter帐户。系统将提示您将密钥文件下载为 file.json。
# Add keyfile to the arweave.app wallet#
将密钥文件添加到 arweave.app 钱包
https://arweave.app/addhttps://arweave.app/add
Click the import keyfile icon. And load your keyfile into the wallet app.单击导入密钥文件图标。并将您的密钥文件加载到钱包应用程序中。
When your keyfile is imported, you will be directed to the wallet view, click the send button and select a file to upload. Then click the send button.导入密钥文件后,您将被引导至钱包视图,单击发送按钮并选择要上传的文件。然后点击发送按钮。
This guide walks you through the most simple way to get data on to the permaweb using a command-line interface (CLI).本指南将引导您使用命令行界面 (CLI) 以最简单的方式将数据传输到 permaweb。
Anyone in the community is welcome to contribute to the Permaweb Cookbook, as community members we want a high quality reference guide of little snack bite sized nuggets of information. Below is a step by step workflow of how anyone can contribute to this project.欢迎社区中的任何人为 Permaweb Cookbook 做出贡献,作为社区成员,我们需要一份高质量的参考指南,其中包含小点心大小的信息块。以下是任何人如何为该项目做出贡献的分步工作流程。
Here are some suggestions on tone and style from some contributors:以下是一些贡献者对语气和风格的一些建议:
TIP提示
In writing them, I'm getting a feeling for the tone that's appropriate for each. CoreConcepts should be rather textbook like, neutral voice, objective. "This is how Arweave works" For Guides, I think it's ok to have a more personal voice. Refer to the reader as "you" and speak in the collaborative voice "next we'll take a look at..." This may just be personal preference, but in general I feel this tone much more supportive and accessible when following a longer form guide. Indeed, its the voice that most popular tutorials from other ecosystems are written in. For Resources, I think it shares the same voice as core concepts, with a preference for brevity.在写它们的过程中,我对适合它们的语气有了一种感觉。 CoreConcepts 应该像教科书一样,中立的声音,客观的。 “这就是 Arweave 的工作方式” 对于 Guides,我认为拥有更个人化的声音是可以的。称呼读者为“你”,并用合作的语气说话“接下来我们将看看……”这可能只是个人喜好,但总的来说,我觉得这种语气在听了更长的时间后更支持和容易接受表格指南。事实上,其他生态系统中最受欢迎的教程都是用这种语气编写的。对于资源,我认为它与核心概念具有相同的语气,并且更倾向于简洁。
dmacdmac
TIP提示
Conceptual and referencial data should have a more cold scientific tone and guides should be a supportive or even humorous tone. Longer form content needs to pull readers in without them zoning out.概念和参考数据应该有更冷酷的科学语气,指南应该是支持甚至幽默的语气。更长的形式内容需要吸引读者而不让他们走神。
Arch_Druid大德鲁伊
# More information about contributing check out the repo style guide#
有关贡献的更多信息,请查看回购风格指南
Do you think a permaweb core concept is missing? Create a issue at Githubopen in new window or consider contributing你认为缺少 permaweb 核心概念吗?在 Github 创建问题
在新窗口中打开
或考虑贡献
When uploading files to Arweave each file is assigned its own unique transaction ID. By default these ID's aren't grouped or organized in any particular manner.将文件上传到 Arweave 时,每个文件都被分配了自己唯一的交易 ID。默认情况下,这些 ID 不会以任何特定方式分组或组织。
These transaction ID's are a bit unwieldy and make it difficult to find all of your relevant files. Without a path manifest, if you uploaded 100 pictures of your cat you would need to keep track of 100 different IDs and links!这些交易 ID 有点笨拙,很难找到所有相关文件。如果没有路径清单,如果您上传了 100 张您的猫的照片,您将需要跟踪 100 个不同的 ID 和链接!
Path Manifests are a way to link multiple transactions together under a single base transaction ID and give them human readable file names. In relation to the cat example, you could have one base transaction ID to remember and use it like a folder - accessing your cat pictures with more memorable filenames like {base id}/cat1.jpgopen in new window, {base id}/cat2.jpgopen in new window, etc.路径清单是一种在单个基本交易 ID 下将多个交易链接在一起并为它们提供人类可读文件名的方法。关于猫的例子,你可以有一个基本的事务 ID 来记住并像文件夹一样使用它——使用更容易记住的文件名访问你的猫图片,比如 {base id}/cat1.jpg
在新窗口中打开
, {base id}/cat2.jpg
在新窗口中打开
, ETC。
Creating grouped sets of readable file names is essential for creating practical applications on Arweave, and unlocks the ability to host websites or other file collections as explored in the examples below.创建分组的可读文件名集对于在 Arweave 上创建实际应用程序至关重要,并解锁托管网站或其他文件集合的能力,如下面的示例所示。
This mirrors the common base path approach used by NFT collections when linking to NFT images and metadata on a storage API or IPFS.这反映了 NFT 集合在链接到存储 API 或 IPFS 上的 NFT 图像和元数据时使用的通用基本路径方法。
Source and Further Reading in the official Arweave Path Manifest docs: Arweave Docsopen in new window官方 Arweave Path Manifest 文档中的来源和进一步阅读:Arweave Docs
在新窗口中打开
The permaweb is like the web, but permanent. Developers build on top of permaweb services to create apps and sites that will exist forever on Arweave.permaweb 就像万维网,但它是永久性的。开发人员在 permaweb 服务之上构建,以创建将永远存在于 Arweave 上的应用程序和网站。
Benifits of the permaweb.永久网的好处。
Sites and apps are permanent, you never have to worry about them going away (even if the team supporting them moves on)网站和应用程序是永久性的,您永远不必担心它们会消失(即使支持它们的团队离开)
App developers have to make sure every new version of the app actually adds value, otherwise, why would you switch off the old one.应用程序开发人员必须确保应用程序的每个新版本都真正增加了价值,否则,您为什么要关闭旧版本。
Because all Permaweb apps share a common storage layer, Arweave, they can all compose with one anther's data.因为所有 Permaweb 应用程序共享一个公共存储层 Arweave,所以它们都可以与一个花药的数据组合。
Your data is owned by your wallet and can follow you from app to app.您的数据归您的钱包所有,可以跟随您从一个应用程序到另一个应用程序。
# Compare Traditional Web vs Permaweb#
比较传统网络与 Permaweb
For more information about the permaweb check out the medium postopen in new window.有关 permaweb 的更多信息,请查看媒体帖子
在新窗口中打开
.
A permaweb application is a type of web page or web app that runs in you browser. What makes it a permaweb app is that it is deployed to Arweave and saved forever. Even if the team that developed it moves on users can rest assured the permaweb app will stay online and available. A huge advantage to permaweb apps is that they save their data on Arweave which means it can easily be imported into other apps that might improve on the one your currently using.permaweb 应用程序是一种在您的浏览器中运行的网页或网络应用程序。使它成为 permaweb 应用程序的原因是它被部署到 Arweave 并永久保存。即使开发它的团队继续前进,用户也可以放心,permaweb 应用程序将保持在线和可用。 permaweb 应用程序的一个巨大优势是它们将数据保存在 Arweave 上,这意味着它可以轻松导入到其他应用程序中,这些应用程序可能会改进您当前使用的应用程序。
For a deeper dive into the permaweb check out this article on The Permaweb要更深入地了解 permaweb,请查看 Permaweb 上的这篇文章
The permaweb is a collection of sites, apps, and SmartContracts built on top of the Arweave's Permaweb Services. The core parts of the Permaweb are the following:permaweb 是建立在 Arweave 的 Permaweb 服务之上的网站、应用程序和智能合约的集合。 Permaweb 的核心部分如下:
Gateway Service (ex. arweave.net, arweave.live, ar.io)网关服务(例如 arweave.net、arweave.live、ar.io)
Bundling Service (ex. bundlr.network)捆绑服务(例如 bundlr.network)
Gateway services are are the bridge between data on Arweave and displaying data in the browser. Gateways often provide indexing service along side serving transaction data, exposing graphQL endpoints for querying Arewave transactions.网关服务是 Arweave 上的数据和在浏览器中显示数据之间的桥梁。网关通常在提供交易数据的同时提供索引服务,公开 graphQL 端点以查询 Arewave 交易。
Bundling services aggregate transactions into transaction bundles and make sure those bundles are posted directly to Arewave. By using a bundling service like bundlr.network you can post hundreds of thousands of transactions in a single Arweave block.捆绑服务将交易聚合成交易包,并确保这些包直接发布到 Arewave。通过使用像 bundlr.network 这样的捆绑服务,您可以在一个 Arweave 块中发布数十万个交易。
Sequencers enables high performance for SmartWeave Contracts to calculate business logic stored on the Arweave network.Sequencer 为 SmartWeave 合约提供高性能,以计算存储在 Arweave 网络上的业务逻辑。
Indexing services listen to all the transactions on Arweave and import them into an indexed database suitble for fast querying. They then expose a graphQL endpoint so permaweb apps can make optimized queries for Arweave data.索引服务监听 Arweave 上的所有交易并将它们导入适合快速查询的索引数据库。然后他们公开一个 graphQL 端点,以便 permaweb 应用程序可以对 Arweave 数据进行优化查询。
These services work together to form the Permaweb Services Layer and gives developers the power to build fully decentralized applications on the permaweb.这些服务共同构成 Permaweb 服务层,并赋予开发人员在 permaweb 上构建完全去中心化应用程序的能力。
Approaching application development with the permaweb is similar to Single Page Application development, the application consists of frontend functionality that is executed in a web browser, and uses GraphQL (Read/Query), Bundlr (Write), and SmartWeave (Decentralized computation) to make up the business logic and persistance layer of the application.使用 permaweb 进行应用程序开发类似于单页应用程序开发,该应用程序由在 Web 浏览器中执行的前端功能组成,并使用 GraphQL(读取/查询)、Bundlr(写入)和 SmartWeave(分散计算)来制作建立应用程序的业务逻辑和持久层。
By leveraging modern web application frameworks and the Path Manifest specification, developers can deploy web sites and applications to the permaweb.通过利用现代 Web 应用程序框架和 Path Manifest 规范,开发人员可以将网站和应用程序部署到 permaweb。
To learn more about creating and deploying Permaweb Apps, check out our starter kits in your favorite framework:要了解有关创建和部署 Permaweb 应用程序的更多信息,请在您最喜欢的框架中查看我们的入门工具包:
There are several ways to post transactions to Arweave. Each has its own unique affordances and constraints. The diagram below illustrates the four main approaches to posting transactions.有几种方法可以将交易发布到 Arweave。每个人都有自己独特的能力和限制。下图说明了过帐交易的四种主要方法。
Direct to Peer,Direct to Gateway, Bundled, and Dispatched.直接对等、直接对网关、捆绑和分派。
Guaranteed Transactions保证交易
If you are posting a high volume of transactions or you want your transactions to be confirmed immediately consider using a bundling service. Transactions posted via a bundler are confirmed immediately and available within milliseconds. The service holds onto the transactions until they are confirmed on-chain. If the transactions are not included in the most recent block the bundling service re-posts them with each new block until tye are confirmed.如果您要发布大量交易或希望立即确认您的交易,请考虑使用捆绑服务。通过捆绑器发布的交易会立即得到确认,并在几毫秒内可用。该服务会保留交易,直到它们在链上得到确认。如果交易没有包含在最近的区块中,捆绑服务会在每个新区块中重新发布它们,直到交易被确认。
Transactions posted directly to Arweave come in two varieties wallet-to-wallet transactions and data transactions. The first transfers AR tokens between wallet addresses. The second posts data to Arweave and pays the associated storage costs.直接发布到 Arweave 的交易分为钱包到钱包交易和数据交易两种。第一个在钱包地址之间转移 AR 代币。第二个将数据发布到 Arweave 并支付相关的存储费用。
Interestingly, data transactions may also transfer AR tokens to a wallet address while paying storage costs at the same time.有趣的是,数据交易也可能在支付存储费用的同时将 AR 代币转移到钱包地址。
All transactions allow the user to specify up to 2KB worth of metadata in the form of custom tags.所有交易都允许用户以自定义标签的形式指定最多 2KB 的元数据。
Transactions may be posted directly to an Arweave peer (mining node). This is perhaps the most decentralized means of posting a transaction as clients can choose what peer they wish to post to.交易可以直接发布到 Arweave 节点(挖矿节点)。这可能是发布交易最去中心化的方式,因为客户可以选择他们希望发布到的节点。
This approach is not without drawbacks. Peers may come and go making it difficult to reliably post transactions from an app. While it's possible to query a list of active peers and choose one before posting it adds overhead and friction to the process. Additionally, transactions posted to peers are only queryable at the gateway after being mined in a block. This introduces a 1-2 minute delay between posting the transaction to a peer and it being available to read in a browser from a gateway.这种方法并非没有缺点。同行可能来来去去,因此很难可靠地从应用程序发布交易。虽然可以在发布之前查询活动对等点列表并选择一个,但这会增加流程的开销和摩擦。此外,发布到对等方的交易只能在区块中被挖掘后在网关处查询。这在将事务发布到对等点和可从网关在浏览器中读取之间引入了 1-2 分钟的延迟。
For the above reasons, developers tend to configure arweave-js to point to a gateway when posting direct transactions as the optimistic cache at the gateway makes the transaction available almost immediately.由于上述原因,开发人员倾向于将 arweave-js 配置为在发布直接交易时指向网关,因为网关处的乐观缓存使交易几乎立即可用。
Gateways sit between clients and Arweave's network of peers. One of the primary functions of the gateway is to index transactions and optimistically cache the data posted to the network while waiting for it to be included in a block. This makes the transaction queryable in a "Pending" state almost instantly which allows applications built on top of a gateway to be more responsive. There is still a risk of transactions dropping out of the optimistic cache if they are not mined in a block by the peers.网关位于客户端和 Arweave 的对等网络之间。网关的主要功能之一是索引交易并乐观地缓存发布到网络的数据,同时等待它被包含在一个块中。这使得事务几乎可以立即在“待定”状态下查询,从而允许构建在网关之上的应用程序更具响应性。如果交易没有被对等方在一个区块中开采,交易仍然存在从乐观缓存中删除的风险。
An example of how to post a direct transaction using arweave-js can be found in this guide.可以在本指南中找到有关如何使用 arweave-js 发布直接交易的示例。
Services built on top of Arweave that provide additional utility for Permaweb builders are sometimes called Permaweb Services. A bundler is one such service. Bundlers take multiple individual transactions and bundle them together into a single transaction that is posted directly to Arweave. In this way a single transaction at the protocol level can contain tens of thousands of bundled transactions. There is one restriction, however, only data transactions can be included in a bundle. Wallet-to-wallet transactions (that transfer AR tokens between wallet addresses) must be done as individual transactions posted directly to Arweave.构建在 Arweave 之上的为 Permaweb 构建器提供附加实用程序的服务有时称为 Permaweb 服务。捆绑器就是这样一种服务。捆绑器将多个单独的交易捆绑在一起,形成一个直接发布到 Arweave 的单一交易。通过这种方式,协议级别的单个交易可以包含数以万计的捆绑交易。但是,有一个限制,捆绑包中只能包含数据交易。钱包到钱包的交易(在钱包地址之间转移 AR 代币)必须作为直接发布到 Arweave 的个人交易来完成。
Another difference when using a bundling service like bundlr.networkopen in new window is that you must make a small deposit on the bundler node you intend to use prior to posting transactions. This enables the bundler service to charge for many small (or large) uploads without the overhead of settling AR tokens transfers directly on Arweave each time.使用像 bundlr.network 这样的捆绑服务时的另一个区别
在新窗口中打开
是您必须在发布交易之前在您打算使用的捆绑器节点上存入少量存款。这使得捆绑服务能够对许多小的(或大的)上传收费,而无需每次直接在 Arweave 上结算 AR 代币传输的开销。
When transactions are posted to bundlr.network they are also appear in the optimistic cache of connected gateways so they are available to query in a matter of milliseconds.当事务发布到 bundlr.network 时,它们也会出现在连接网关的乐观缓存中,因此它们可以在几毫秒内进行查询。
An example of how to post bundled transactions using bundlr.network/client can be found in this guide.可以在本指南中找到有关如何使用 bundlr.network/client 发布捆绑交易的示例。
Another way to post bundled transactions is from the browser. While browsers enforce some constraints around the size of data that can be uploaded, browser based wallets are able to post transactions to bundlers. Arweave browser wallets implement a dispatch() API method. If you are posting small transactions (100KB or less) you can use the wallets dispatch() method to take advantage of bundled transactions even if bundlr.network/client isn't packaged with your application.发布捆绑交易的另一种方式是从浏览器。虽然浏览器对可以上传的数据大小实施了一些限制,但基于浏览器的钱包能够将交易发布到捆绑器。 Arweave 浏览器钱包实现了一个 dispatch() API 方法。如果您要发布小额交易(100KB 或更少),即使 bundlr.network/client 未与您的应用程序打包在一起,您也可以使用 wallets dispatch() 方法来利用捆绑交易。
An example of how to post a 100KB or less bundled transaction with an Arweave wallets dispatch() method can be found in this guide.可以在本指南中找到有关如何使用 Arweave 钱包 dispatch() 方法发布 100KB 或更小的捆绑交易的示例。
# Posting Transactions using arweave-js#
使用 arweave-js 发布交易
Arweave native transactions can be posted directly to a node or gateway using the arweave-js package.Arweave 本机事务可以使用 arweave-js 包直接发布到节点或网关。
Arweave scales though the use of transaction bundles. These bundles make it possible for each block to contain a nearly unlimited number of transactions. Without the use of bundles, Arweave blocks are limited 1000 transactions per block (with new blocks produced every ~2 minutes). If your use case exceeds this capacity you may experience dropped transactions. Under these circumstances please consider using bundlr.network or similar services to bundle your transactions.Arweave 通过使用交易包进行扩展。这些捆绑包使每个区块都可以包含几乎无限数量的交易。在不使用捆绑包的情况下,Arweave 块限制为每个块 1000 个事务(每约 2 分钟产生新块)。如果您的用例超过此容量,您可能会遇到交易丢失的情况。在这些情况下,请考虑使用 bundlr.network 或类似服务来捆绑您的交易。
# Installing the arweave-js Package#
安装 arweave-js 包
Direct Layer 1 transactions are posted using the arweave-js library.使用 arweave-js 库发布直接第 1 层交易。
import Arweave from'arweave';import fs from"fs";// load the JWK wallet key file from disklet key =JSON.parse(fs.readFileSync("walletFile.txt").toString());// initialize an arweave instanceconst arweave = Arweave.init({});
# Posting a wallet-to-wallet Transaction#
发布钱包到钱包交易
A basic transaction to move AR tokens from one wallet address to another.将 AR 代币从一个钱包地址转移到另一个钱包地址的基本交易。
// create a wallet-to-wallet transaction sending 10.5AR to the target addresslet transaction =await arweave.createTransaction({target:'1seRanklLU_1VTGkEk7P0xAwMJfA7owA1JHW5KyZKlY',quantity: arweave.ar.arToWinston('10.5')}, key);// you must sign the transaction with your key before postingawait arweave.transactions.sign(transaction, key);// post the transactionconst response =await arweave.transactions.post(transaction);
This example illustrates how load a file from disk and create a transaction to store its data on the network. You can find the current price the network is charging at https://ar-fees.arweave.devopen in new window此示例说明如何从磁盘加载文件并创建事务以将其数据存储在网络上。您可以在 https://ar-fees.arweave.dev 找到网络收取的当前价格
在新窗口中打开
// load the data from diskconst imageData = fs.readFileSync(`iamges/myImage.png`);// create a data transactionlet transaction =await arweave.createTransaction({data: imageData
}, key);// add a custom tag that tells the gateway how to serve this data to a browser
transaction.addTag('Content-Type','image/png');// you must sign the transaction with your key before postingawait arweave.transactions.sign(transaction, key);// create an uploader that will seed your data to the networklet uploader =await arweave.transactions.getUploader(transaction);// run the uploader until it completes the upload.while(!uploader.isComplete){await uploader.uploadChunk();}
For an overview of all the ways you can post transactions, see the Posting Transactions section of the cookbook.有关您可以发布交易的所有方式的概述,请参阅说明书的发布交易部分。
For a more detailed description of all arweave-js's features see the documentation on githubopen in new window有关所有 arweave-js 功能的更详细描述,请参阅 github 上的文档
在新窗口中打开
# Posting Transactions using bundlr.network#
使用 bundlr.network 发布交易
Posting transactions to bundlr.network can be accomplished using the bundlr.network/client javascript package. Bundling services enable guaranteed confirmation of posted transactions as well as supporting many thousands of transactions per block though the use of transaction bundles.可以使用 bundlr.network/client javascript 包将事务发布到 bundlr.network。捆绑服务可以保证已发布交易的确认,并通过使用交易捆绑支持每个区块数以千计的交易。
# Installing the bundlr.network/client#
安装 bundlr.network/client
To install bundlr.network/client run安装 bundlr.network/client 运行
A difference between posting Layer 1 and bundled Layer 2 transactions is that when using bundlr you must make a deposit on the bundlr node ahead of time. This deposit can be made using AR tokens or a variety of other crypto currencies. Another difference is that the bundlr service guarantees your data will arrive on chain.发布第 1 层交易和捆绑第 2 层交易之间的区别在于,使用 bundlr 时,您必须提前在 bundlr 节点上进行存款。可以使用 AR 代币或各种其他加密货币进行此存款。另一个区别是 bundlr 服务保证你的数据将到达链上。
import Bundlr from'@bundlr-network/client';import fs from"fs";// load the JWK wallet key file from disklet key =JSON.parse(fs.readFileSync("walletFile.txt").toString());// initailze the bundlr SDKconst bundlr =newBundlr("http://node1.bundlr.network","arweave", key);
// load the data from diskconst imageData = fs.readFileSync(`images/myImage.png`);// add a custom tag that tells the gateway how to serve this data to a browserconst tags =[{name:"Content-Type",value:"image/png"},];// create the bundled transaction and sign itconst tx = bundlr.createTransaction(imageData,{ tags });await tx.sign();// upload the transaction to bundlr for inclusion in a bundle to be postedawait tx.upload();
# Posting a Transaction Using Dispatch#
使用 Dispatch 发布交易
Arweave Browser wallets have the concept of dispatching transactions. If the transaction is under 100KB in size it can be posted for free!Arweave 浏览器钱包具有调度交易的概念。如果交易小于 100KB,可以免费发布!
This can be done without any package dependencies for the client app. As long as the user has a browser wallet active and the data is less than 100KB, dispatched transactions are free and guaranteed to be confirmed on the network.这可以在客户端应用程序没有任何包依赖性的情况下完成。只要用户有一个浏览器钱包处于活动状态并且数据小于 100KB,发送的交易是免费的,并且保证在网络上得到确认。
// use arweave-js to create a transactionlet tx =await arweave.createTransaction({data:"Hello World!"})// add some custom tags to the transaction
tx.addTag('App-Name','PublicSquare')
tx.addTag('Content-Type','text/plain')
tx.addTag('Version','1.0.1')
tx.addTag('Type','post')// use the browser wallet to dispatch() the transactionlet result =await window.arweaveWallet.dispatch(tx);// log out the transactino id
console.log(result.id);
It isn't enough to store data permanently, for Arweave to be useful the data also needs to be discoverable and retrievable. This guide summarizes the different approaches to querying data on Arweave.永久存储数据是不够的,要使 Arweave 有用,数据还需要可发现和可检索。本指南总结了在 Arweave 上查询数据的不同方法。
Over time, indexing services that implement a GraphQL interface have became the preferred method for querying transaction data on Arweave. An indexing service reads transaction and block headers as they are added to the network (usually from a full Arweave node which the service operates). Once read, the header info is inserted into a database where it can be indexed and efficiently queried. The indexing service uses this database to provide a GraphQL endpoint for clients to query.随着时间的推移,实现 GraphQL 接口的索引服务已经成为在 Arweave 上查询交易数据的首选方法。索引服务在将交易和区块头添加到网络时读取它们(通常来自服务运行的完整 Arweave 节点)。读取后,标题信息将被插入到数据库中,可以在其中对其进行索引和高效查询。索引服务使用此数据库为客户端提供 GraphQL 端点以供查询。
GraphQL has a few advantages that make it ideal for retrieving query data sets. It enables indexing services to create a single endpoint that can then be used to query all types data. The service is able to return multiple resources in a single request as opposed to making an HTTP request for each resource (like one would with a REST API). With GraphQL, clients can batch multiple requests in a single round-trip and specify exactly what data is needed which increases performance.GraphQL 有一些优势,使其成为检索查询数据集的理想选择。它使索引服务能够创建单个端点,然后可用于查询所有类型的数据。该服务能够在单个请求中返回多个资源,而不是为每个资源发出 HTTP 请求(就像使用 REST API 那样)。借助 GraphQL,客户端可以在单次往返中对多个请求进行批处理,并准确指定需要哪些数据以提高性能。
The following GraphQL example queries all the transaction ids from a given owners wallet address that have a "Type" tag with a value of "manifest". For more information about tags, read the guide on Transaction Tags.以下 GraphQL 示例查询来自给定所有者钱包地址的所有交易 ID,这些地址具有值为“清单”的“类型”标签。有关标签的更多信息,请阅读交易标签指南。
Each piece of data uploaded to Arweave has its own unique transaction id and is included in a unique block which is then added to the blockchain. The data associated with each transaction is split up into 256KB chunks and appended sequentially to Arweave's dataset. It is possible to walk back, block by block, from the current blockopen in new window and inspect each one for the transaction id in question. Once found, the chunks offsets can be retrieved from the block and used to request chunks directly from an Arweave peer. This is the lowest level way to locate and read data on the network. Thankfully, less labor intensive approaches like GraphQL are available.上传到 Arweave 的每条数据都有自己唯一的交易 ID,并包含在一个唯一的块中,然后将其添加到区块链中。与每笔交易相关的数据被分成 256KB 的块,并按顺序附加到 Arweave 的数据集中。可以从当前块逐块返回
在新窗口中打开
并检查每个交易 ID 是否有问题。一旦找到,就可以从块中检索块偏移量,并用于直接从 Arweave 对等方请求块。这是在网络上定位和读取数据的最低级别方法。值得庆幸的是,像 GraphQL 这样的劳动密集型方法是可用的。
ARQL is deprecated and replaced by GraphQL queries at a gateway or indexing service. Some peers may still honor ARQL requests but the availability and accuracy of results are not guaranteed.ARQL 在网关或索引服务中被弃用并替换为 GraphQL 查询。一些同行可能仍然尊重 ARQL 请求,但不保证结果的可用性和准确性。
Arweave Query Language (ARQL) was used early on in Arweave's development. Along side blocks and chunks, peers also maintained a SQL database which indexed individual transactions. Clients could query a peer using ARQL and get back transaction data. The following is an example ARQL query syntax.Arweave 查询语言 (ARQL) 在 Arweave 的早期开发中被使用。除了块和块之外,对等点还维护一个 SQL 数据库,该数据库为单个事务编制索引。客户端可以使用 ARQL 查询对等点并取回交易数据。以下是 ARQL 查询语法示例。
let get_mail_query ={op:'and',expr1:{op:'equals',expr1:'to',expr2: address
},expr2:{op:'equals',expr1:'App-Name',expr2:'permamail'}}const res =awaitthis.arweave.api.post(`arql`, get_mail_query)
This approach to querying was sufficient the weave dataset was small and easy to index. As Arweave adoption accelerated, indexing the data set and responding to ARQL queries resulted in increasing computational costs. Over time as mining became more and more competitive, peers became less and less likely to be able to afford to offer the ARQL service. This ultimately became the impetus for indexing services and the GraphQL querying common on Arweave today.这种查询方法足够了,因为 weave 数据集很小且易于索引。随着 Arweave 的采用加速,索引数据集和响应 ARQL 查询导致计算成本增加。随着时间的推移,随着挖矿竞争变得越来越激烈,同行越来越不可能负担得起提供 ARQL 服务的费用。这最终成为了索引服务和 Arweave 上常见的 GraphQL 查询的推动力。
There is a pathway back to being able to query data directly from peers however. The Permaweb Payments Protocol (P3)open in new window is a specification developed by the community to enable clients to pay for service. Using P3, peers wishing to offer indexing service could afford to operate it profitably it by charging for the service.然而,有一种途径可以直接从同行查询数据。 Permaweb 支付协议 (P3)
在新窗口中打开
是由社区开发的规范,使客户能够为服务付费。使用 P3,希望提供索引服务的同行可以通过对服务收费来负担得起运营盈利。
SmartWeave is the name given to the dominant SmartContract paradigm on Arweave. A unique property of SmartWeave contracts is that the current state of the contract is provided by a process of "lazy evaluation". This means that instead of Arweave mining nodes constantly evaluating the current state of all contracts, a client reading a contract evaluates the state for themselves.SmartWeave 是 Arweave 上占主导地位的 SmartContract 范式的名称。 SmartWeave 合约的一个独特属性是合约的当前状态由“惰性评估”过程提供。这意味着,与 Arweave 挖矿节点不断评估所有合约的当前状态不同,读取合约的客户端会自行评估状态。
# Why is SmartWeave important?#
为什么 SmartWeave 很重要?
The state and logic of decentralized applications need to be as censorship resistant, permanent and verifiable as the rest of their data. SmartWeave enables developers to write smart contracts that encapsulate their apps state and logic on-chain and execute it in a trustless verifiable way. This is no small feat as the Arweave protocol does not include incentives for nodes to evaluate smart contract state for the network.去中心化应用程序的状态和逻辑需要像其他数据一样具有抗审查性、永久性和可验证性。 SmartWeave 使开发人员能够编写智能合约,将其应用程序状态和逻辑封装在链上,并以无需信任的可验证方式执行。这是一项不小的壮举,因为 Arweave 协议不包括激励节点评估网络的智能合约状态。
SmartWeave provides an immutable append-only pattern for contract interactions that leverages permanent storage to hold onto their state. The result is a fully decentralized on-chain state machine that can give protocols and applications dynamic functionality in a permissionless and trustless way. By using SmartWeave, developers can create smart contracts that are stored on Arweave and are guaranteed not to change over time. This allows them to build Permaweb applications with dynamic functionality that can be used in a permissionless and trustless manner.SmartWeave 为合约交互提供了一种不可变的仅附加模式,利用永久存储来保存它们的状态。结果是一个完全去中心化的链上状态机,可以以无需许可和无需信任的方式为协议和应用程序提供动态功能。通过使用 SmartWeave,开发人员可以创建存储在 Arweave 上并保证不会随时间变化的智能合约。这使他们能够构建具有动态功能的 Permaweb 应用程序,这些应用程序可以以无需许可和无需信任的方式使用。
There are several reasons why developers might choose to use SmartWeave to implement the logic for their permaweb applications:开发人员可能会选择使用 SmartWeave 来实现他们的 permaweb 应用程序的逻辑有几个原因:
Decentralized storage: SmartWeave is built on Arweave, which means that applications created using SmartWeave will be stored on a distributed network of nodes rather than on a centralized server. This can make them more resistant to censorship, tampering, and other forms of interference.去中心化存储:SmartWeave 建立在 Arweave 之上,这意味着使用 SmartWeave 创建的应用程序将存储在分布式节点网络上,而不是集中式服务器上。这可以使它们更能抵抗审查、篡改和其他形式的干扰。
Lazy evaluation: The lazy evaluation feature of SmartWeave contracts allows for efficient and scaleable execution. Instead of Arweave nodes constantly evaluating the state of a contract, the client reading the contract is responsible for evaluating the state, leveraging the users processing power instead of the networks nodes.惰性评估:SmartWeave 合约的惰性评估功能允许高效且可扩展的执行。与 Arweave 节点不断评估合同状态不同,读取合同的客户端负责评估状态,利用用户处理能力而不是网络节点。
Language support: SmartWeave supports a range of programming languages, including JavaScript, TypeScript, Rust, Go, AssemblyScript, and WASM (WebAssembly). This allows developers to use the language they are most familiar with when creating SmartWeave applications.语言支持:SmartWeave 支持多种编程语言,包括 JavaScript、TypeScript、Rust、Go、AssemblyScript 和 WASM (WebAssembly)。这允许开发人员在创建 SmartWeave 应用程序时使用他们最熟悉的语言。
Data durability: Arweave is designed to store data in a way that makes it highly durable and long-lasting. This can be useful for applications that need to store data over a long period of time, such as historical records or scientific data.数据持久性:Arweave 旨在以一种高度耐用和持久的方式存储数据。这对于需要长期存储数据的应用程序非常有用,例如历史记录或科学数据。
Economic model: Arweave uses a unique economic model based on the concept of permanent storage that incentivizes miners to store data indefinitely. This can help ensure the long-term viability and durability of permaweb applications created using SmartWeave.经济模型:Arweave 使用基于永久存储概念的独特经济模型,激励矿工无限期地存储数据。这有助于确保使用 SmartWeave 创建的 permaweb 应用程序的长期可行性和持久性。
SmartWeave contracts, at their core, are built from an initial contract state, with edits, additions, and subtractions using transaction tags.SmartWeave 合约的核心是从初始合约状态构建,使用交易标签进行编辑、添加和删除。
SmartWeave SDK's such as Warp (previously RedStone), are used to query for these transactions to build contract state locally, modifying the contract state with each transaction. The Evaluator (Warp) uses tags to query for a contracts transactions; It knows a transaction is part of the contract by way of the App-Name tag, and the Contract tag.SmartWeave SDK,例如 Warp(以前称为 RedStone),用于查询这些交易以在本地构建合约状态,修改每笔交易的合约状态。 Evaluator(Warp)使用标签来查询合约交易;它通过 App-Name 标签和 Contract 标签知道交易是合同的一部分。
Here is an example of a contract interaction .下面是一个合约交互的例子。
The App-Name says its a Smartweave ACTION .App-Name 说它是一个 Smartweave ACTION 。
The Contract tag gives the specific transaction ID of the initial contract state.Contract标签给出初始合约状态的具体交易ID。
The Input tag gives the contract its function to execute and any other data it needs:Input 标签为合约提供了执行的功能以及它需要的任何其他数据:
The resulting state is the current contract state, which the SDK on the client side can use to calculate user balances, contract owners, and other contract specific details. Once the caller has a validated contract state they can build an interaction for the user to deploy to the chain, which upon mining or indexing on a Gateway will be included the next time someone builds the contract state.结果状态是当前合约状态,客户端的 SDK 可以使用它来计算用户余额、合约所有者和其他合约特定细节。一旦调用者拥有经过验证的合约状态,他们就可以为用户构建交互以部署到链上,在网关上进行挖掘或索引时,下次有人构建合约状态时将包含该交互。
Theres quite a few ecosystem projects leveraging SmartWeave SmartContracts, but here are some of note:有相当多的生态系统项目利用 SmartWeave SmartContracts,但这里有一些值得注意的地方:
Warpopen in new window | Main provider of SmartWeave SDK's, tutorials, and helps maintain the SmartWeave protocol.经
在新窗口中打开
| SmartWeave SDK、教程的主要提供者,并帮助维护 SmartWeave 协议。
EXMopen in new window | Execution Machine (EXM) is a developer platform that powers the creation and usage of highly available and highly performant applications within a decentralized environment.EXM
在新窗口中打开
| Execution Machine (EXM) 是一个开发人员平台,它支持在去中心化环境中创建和使用高可用性和高性能的应用程序。
Permapagesopen in new window | Permanent webpage creation tool, ArNS purchase portal, and ANT creation portal. Your profile on the permaweb.永久地图
在新窗口中打开
|永久网页创建工具、ArNS购买入口、ANT创建入口。您在 permaweb 上的个人资料。
ArNS // todo: update to arns portal when portal is releasedArNS // todo: 发布门户时更新到 arns 门户
The Arweave Name System (ArNS) is the Smartweave-powered phonebook of the PermaWeb.Arweave 名称系统 (ArNS) 是 PermaWeb 的 Smartweave 驱动的电话簿。
It is a decentralized and censorship-resistant naming system that is enabled by AR.IO Gateways and used to connect friendly names to PermaWeb apps, pages and data.它是一个分散的、抗审查的命名系统,由 AR.IO 网关启用,用于将友好名称连接到 PermaWeb 应用程序、页面和数据。
This system works similarly to traditional DNS, where a user can purchase a name in a registry and DNS Name servers resolve these names to IP addresses.该系统的工作方式与传统 DNS 类似,用户可以在注册表中购买名称,DNS 名称服务器将这些名称解析为 IP 地址。
With ArNS, the registry is decentralized, permanent and stored on Arweave (with Smartweave) and each AR.IO gateway acts as both cache and name resolver. Users can register a name within the ArNS Registry, like "my-name" and set a pointer to any Arweave Transaction ID. AR.IO Gateways will resolve that name as one of their own subdomains, eg. https://laserilla.arweave.net and proxy all requests to the associated Arweave Transaction ID. Each registered name can also have under names associated with it that each point to an Arweave Transaction ID, like https://v1_laserilla.arweave.net, giving even more flexibility and control to its owner.使用 ArNS,注册表是分散的、永久的并存储在 Arweave(使用 Smartweave)上,并且每个 AR.IO 网关都充当缓存和名称解析器。用户可以在 ArNS 注册表中注册一个名称,例如“我的名字”,并设置指向任何 Arweave 交易 ID 的指针。 AR.IO 网关会将该名称解析为它们自己的子域之一,例如。 https://laserilla.arweave.net 并将所有请求代理到关联的 Arweave 交易 ID。每个注册名称还可以有与之关联的名称,每个名称都指向一个 Arweave 交易 ID,例如 https://v1_laserilla.arweave.net,从而为其所有者提供更大的灵活性和控制权。
// TODO: link to smartweave concept //// TODO:链接到 smartweave 概念 //
ArNS uses the Smartweave protocol manage its name records. Each record, or name, is leased by a user and tied to an ANT token. You can register multiple ArNS names to a single ANT, but you cannot register multiple ANTs to a single ArNS name - the gateways would'nt know where to point the routing ID.ArNS 使用 Smartweave 协议管理其名称记录。每个记录或名称都由用户租用并绑定到 ANT 令牌。您可以将多个 ArNS 名称注册到单个 ANT,但不能将多个 ANT 注册到单个 ArNS 名称 - 网关不知道将路由 ID 指向何处。
ArNS names can be up to 32 characters, including numbers [0-9], letters [a-z], and dashes [-]. The dashes cannot be trailing dashes, e.g. -myname.ArNS 名称最多可以包含 32 个字符,包括数字 [0-9]、字母 [a-z] 和破折号 [-]。破折号不能是尾部破折号,例如-我的名字。
ANTs are a crucial part of the ArNS ecosystem - they are the actual key to owning an ArNS name. When you register an ArNS name to an ANT, the ANT then becomes the transfer method for that name. The ArNS registry does not care who owns the ANT, it simply knows what name ANT it belongs to.ANT 是 ArNS 生态系统的重要组成部分——它们是拥有 ArNS 名称的实际关键。当您将 ArNS 名称注册到 ANT 时,ANT 将成为该名称的传输方法。 ArNS 注册表不关心谁拥有 ANT,它只知道它属于哪个名称的 ANT。
Within ANTs you can build out whatever functionality you wish, within the scope ArNS registry approved source code transaction list. Up to and including NFT's, PST's, DAO's, or full on applications.在 ANTs 中,您可以在 ArNS 注册表批准的源代码交易列表范围内构建您想要的任何功能。直至并包括 NFT、PST、DAO 或完整的应用程序。
Undernames are records held and managed by your ANT (Arweave Name Token). These records can be created and managed without even owning an ARNS name, and will be transferred along with the ant when sent to a new owner. Likewise if your ArNS name expires, and you register your ANT to a new ArNS name, all your undername will remain intact.Undernames 是由您的 ANT(Arweave 名称令牌)持有和管理的记录。这些记录甚至可以在没有 ARNS 名称的情况下创建和管理,并且在发送给新所有者时将与 ant 一起转移。同样,如果您的 ArNS 名称过期,并且您将 ANT 注册到一个新的 ArNS 名称,您的所有姓名都将保持不变。
Example: you own oldName.arweave.net.示例:您拥有 oldName.arweave.net。
then: You create the undername "my" - my_oldName.arweave.net.然后:您创建了“我的”这个名字 - my_oldName.arweave.net。
then: oldName.arweave.net expires, and you register newName.arweave.net to your ANT.然后:oldName.arweave.net 过期,您将 newName.arweave.net 注册到您的 ANT。
now: my_ undername is accessable on newName - my_newName.arweave.net.现在:my_ undername 可在 newName - my_newName.arweave.net 上访问。
Below is an example of an ANT contract State:下面是一个 ANT 合约状态的例子:
the base "@" record is the initial routing id for the ANT. if you registered 'my-name' to this ANT, and tried to access it via my-name.arweave.net, you would be redirected to the @ record's transactionId.基本“@”记录是 ANT 的初始路由 ID。如果您向此 ANT 注册了“我的名字”,并尝试通过 my-name.arweave.net 访问它,您将被重定向到 @ 记录的 transactionId。
if you tried to access undername1_my-name.arweave.net, you would get 'undername1's transactionId.如果您尝试访问 undername1_my-name.arweave.net,您将获得“undername1 的交易 ID”。
ANT's, in theory, have an UNLIMITED number of undernames. However, how many will be served depends on which tier is used with your ArNS name.理论上,ANT 有无限多的名字。但是,服务的数量取决于您的 ArNS 名称使用的层级。
Atomic assets are a type of digital asset that are built on blockchain technology and adhere to certain standards. The core principles of the Atomic Asset standard include:原子资产是一种基于区块链技术并遵循一定标准的数字资产。原子资产标准的核心原则包括:
Non-Fungible: Each atomic asset is unique and cannot be replaced by another asset. This means that each atomic asset has a unique identifier that sets it apart from other assets.不可替代:每个原子资产都是唯一的,不能被其他资产取代。这意味着每个原子资产都有一个唯一的标识符,将其与其他资产区分开来。
Immutable: Atomic assets cannot be altered or tampered with once they have been created. This ensures the integrity and authenticity of the asset.不可变的:原子资产一旦创建就无法更改或篡改。这确保了资产的完整性和真实性。
Transferability: Atomic assets can be easily transferred and traded between users on the blockchain. This allows for the quick and efficient exchange of assets.可转移性:原子资产可以在区块链上的用户之间轻松转移和交易。这允许快速有效地交换资产。
Decentralization: Atomic assets are stored and managed on a decentralized blockchain network, meaning that there is no central authority controlling or regulating the assets.去中心化:原子资产在去中心化的区块链网络上存储和管理,这意味着没有中央机构控制或监管资产。
Transparency: Atomic assets are transparent and the ownership and transaction history of the assets can be easily tracked and verified on the blockchain.透明性:原子资产是透明的,资产的所有权和交易历史可以在区块链上轻松追踪和验证。
Security: Atomic assets are built on blockchain technology, which is highly secure, it ensures that assets are protected against fraud and hacking.安全性:原子资产建立在高度安全的区块链技术之上,确保资产免受欺诈和黑客攻击。
# The most important principle is the following#
最重要的原则如下
An atomic asset associates one unique identifier, known as a "non-fungible token" (NFT) with the data and smart contract that define the asset. The NFT serves as a digital certificate of authenticity and ownership for the atomic asset, and it is stored on the blockchain.原子资产将一个称为“不可替代令牌”(NFT)的唯一标识符与定义资产的数据和智能合约相关联。 NFT 作为原子资产真实性和所有权的数字证书,存储在区块链上。
The data and smart contract associated with the atomic asset define the characteristics and behavior of the asset. For example, the data may include information such as the asset's name, image, and metadata. The smart contract, on the other hand, is a set of programmed rules and conditions that govern how the asset can be bought, sold, and traded on the blockchain.与原子资产关联的数据和智能合约定义了资产的特征和行为。例如,数据可能包括资产名称、图像和元数据等信息。另一方面,智能合约是一组程序化的规则和条件,用于管理资产在区块链上的买卖和交易方式。
The combination of the NFT, data, and smart contract creates a unique and verifiable digital asset that can be easily transferred and traded between users on the blockchain. The NFT acts as the proof of ownership and authenticity for the atomic asset, the data provide information about the asset, and the smart contract governs how the asset can be used and traded.NFT、数据和智能合约的结合创造了一种独特的、可验证的数字资产,可以在区块链上的用户之间轻松转移和交易。 NFT 充当原子资产的所有权和真实性证明,数据提供有关资产的信息,智能合约管理资产的使用和交易方式。
Founders of an application can create a set number of PSTs and distribute them as they see fit - to keep, or sell to investors to raise capital.应用程序的创始人可以创建一定数量的 PST,并在他们认为合适的时候分配它们——保留或出售给投资者以筹集资金。
Protocols can offer PSTs as a reward for contributing work, or completing tasks for the community to incentivize growth.协议可以提供 PST 作为对贡献工作或完成社区任务以激励增长的奖励。
PSTs can also be exchanged between each other on Permaswapopen in new window (currently in testnet), and developers can set up token trading permissions using Verto Flexopen in new window.PST 也可以在 Permaswap 上相互交换
在新窗口中打开
(目前在测试网),开发者可以使用 Verto Flex 设置代币交易权限
在新窗口中打开
.
PSTs work as ‘micro-dividends’. When a protocol is used, a tipping amount is set aside to be distributed amongst holders. The tip is paid out in $AR - not in the currency of the PST. This creates quite a special relationship between the app being developed, and Arweave itself.PST 作为“微红利”发挥作用。使用协议时,会预留小费金额以分配给持有人。小费以 AR 支付,而不是 PST 的货币。这在正在开发的应用程序和 Arweave 本身之间创建了一种非常特殊的关系。
ArDrive is a permaweb application utilitizing their aptly named PST, ARDRIVE.ArDrive 是一个 permaweb 应用程序,利用其恰当命名的 PST,ARDRIVE。
When someone pays $AR to upload data through ArDrive, a 15% community fee is distributed to a single token holder using a random, weighted method.当有人支付 $AR 通过 ArDrive 上传数据时,15% 的社区费用将使用随机、加权的方法分配给单个代币持有者。
A user uploads data -> An ARDRIVE token holder receives $AR -> ARDRIVE token holder can use this $AR to upload files -> cycle repeats. Hopefully this gives you a good idea of one way you could implement your own PST!用户上传数据 -> 一个 ARDRIVE 代币持有者收到 $AR -> ARDRIVE 代币持有者可以使用这个 $AR 上传文件 -> 循环重复。希望这能让您对实现自己的 PST 的一种方式有所了解!
Going straight to viewblock and Sonar by Redstone is most appropriate most likely. Just use links that specifically show PSTs so someone doesn’t have to navigate to find them.直接使用 Viewblock 和 Redstone 的 Sonar 是最合适的。只需使用专门显示 PST 的链接,这样就无需导航即可找到它们。
You can use ViewBlockopen in new window for an etherscan-like experience to view PST contracts, like this one hereopen in new window.您可以使用视图块
在新窗口中打开
获得类似 etherscan 的体验来查看 PST 合约,就像这里的这个
在新窗口中打开
.
Another option is Sonar, an Arweave smart contract explorer built by RedStone Financeopen in new window. View the same contract hereopen in new window.另一种选择是 Sonar,这是由 RedStone Finance 构建的 Arweave 智能合约浏览器
在新窗口中打开
.在此处查看相同的合同
在新窗口中打开
.
Some community members have been discussing calling PSTs “Permaweb Service Tokens”. There is still much to explore with PSTs → join the discussion hereopen in new window (Discord).一些社区成员一直在讨论将 PST 称为“永久网络服务令牌”。 PST 还有很多值得探索的地方 → 在这里加入讨论
在新窗口中打开
(不和谐)。
Arweave can be thought of as a permanent append-only hard drive where each entry on the drive is its own unique transaction. Transactions have a unique ID, signature, and owner address for the address that signed and paid for the transaction to be posted. Along with those header values, the Arweave protocol allows users to tag transactions with custom tags. These are specified as a collection name value pairs appended to the transaction. These tags make it possible to query Arweave and find all the Transactions that include a particular tag or tags. The ability to query and filter transactions is critical to supporting apps built on Arweave.Arweave 可以被认为是一个永久的只能附加的硬盘驱动器,其中驱动器上的每个条目都是它自己唯一的事务。交易具有唯一的 ID、签名和所有者地址,用于为要发布的交易签名和支付的地址。除了这些标头值外,Arweave 协议还允许用户使用自定义标签来标记交易。这些被指定为附加到事务的集合名称值对。这些标签使得查询 Arweave 并找到包含特定标签或标签的所有交易成为可能。查询和过滤交易的能力对于支持基于 Arweave 构建的应用程序至关重要。
Transaction tags are key-value pairs, where the combination of base64URL keys and values must be less than the maximum of 2048 bytes for an arweave native transaction.交易标签是键值对,其中 base64URL 键和值的组合必须小于 arweave 本机交易的最大值 2048 字节。
TIP提示
Bundled transactions have support for more tag space. Transactions posted via bundler.network have up to 4096 bytes of tag space.捆绑交易支持更多标签空间。通过 bundler.network 发布的交易最多有 4096 字节的标签空间。
Some common examples of transaction tags include:交易标签的一些常见示例包括:
Content-Type: Used to specify the MIME type of content for render on the permaweb.Content-Type:用于指定在 permaweb 上呈现的内容的 MIME 类型。
App-Name: This tag describes the app that is writing the dataApp-Name:这个标签描述了正在写入数据的应用程序
App-Version: This tag is the version of the app, paired with App-NameApp-Version:这个标签是应用的版本,与App-Name配对
Unix-Time: This tag is the a unix timestamp, seconds since epoch.Unix-Time:这个标签是一个 unix 时间戳,自纪元以来的秒数。
Title: Used to give a name or brief description of the content stored in the transaction.Title:用于给出交易中存储的内容的名称或简要说明。
Description: Used to provide a longer description of the content.描述:用于提供内容的较长描述。
Transaction tags can be used for a variety of purposes, such as indexing transactions for search, organizing transactions into categories, or providing metadata about the content stored in a transaction.事务标签可用于多种目的,例如为搜索索引事务、将事务组织到类别中或提供有关存储在事务中的内容的元数据。
# Some good things to know about Transaction Tags#
关于交易标签的一些好事
Transaction tags are encoded as Base64URL encoded strings for both the key and value. This makes it possible to post arrays of bytes as keys or values and transfer them safely over http. While it's not human readable without decoding, it shouldn't be considered encryption.交易标签被编码为键和值的 Base64URL 编码字符串。这使得将字节数组作为键或值发布并通过 http 安全地传输它们成为可能。虽然未经解码就无法读取,但不应将其视为加密。
The max total size of Transaction tags for transaction posted directly to Arweave is 2048 bytes. This size is determined by the concatenation of all keys and all values of the transaction tags.直接发布到 Arweave 的交易的交易标签的最大总大小为 2048 字节。此大小由交易标签的所有键和所有值的串联决定。
Transaction tags can be used in GraphQL queries to return a filtered set of transaction items.可以在 GraphQL 查询中使用交易标签来返回一组经过过滤的交易项目。
Most commonly used for SmartWeave Identifiers最常用于 SmartWeave 标识符
Common values are SmartWeaveContract, SmartWeaveAction, and SmartWeaveContractSource常用值有 SmartWeaveContract、SmartWeaveAction 和 SmartWeaveContractSource
App-Version应用版本
The version of this data, it may represent the app consuming this information这个数据的版本,它可能代表了消费这个信息的应用程序
0.3.0 is the current SmartWeave Version0.3.0 是当前的 SmartWeave 版本
Content-Type内容类型
MIME Type to identify the data contained in the transaction用于标识事务中包含的数据的 MIME 类型
const tx =await arweave.createTransaction({ data: mydata })
tx.addTag('Content-Type','text/html')
tx.addTag('Title','My incredible post about Transaction Tags')
tx.addTag('Description','This is one post you do not want to miss!')
tx.addTag('Topic:Amazing','Amazing')
tx.addTag('Type','blog-post')await arweave.transactions.sign(tx, jwk)await arweave.transactions.post(tx)
await bundlr.upload(mydata,[{name:'Content-Type',value:'text/html'},{name:'Title',value:'My incredible post about Transaction Tags'},{name:'Description',value:'This one post you do not want to miss!'},{name:'Topic:Amazing',value:'Amazing'},{name:'Type',value:'blog-post'}])
Understanding how Transaction Tags factor into the Arweave tech stack can provide context on how to solve problems using the Permaweb as an application platform. Tags provide a tool to consume and create common data standards and patterns to encourage a non-rivalous data experience on the Permaweb. The result gives users of the ecosystem the choice of applications to consume and create content as their data is always with the user not the application.了解交易标签如何影响 Arweave 技术堆栈可以提供有关如何使用 Permaweb 作为应用程序平台来解决问题的上下文。标签提供了一种工具来使用和创建通用数据标准和模式,以鼓励 Permaweb 上的非竞争性数据体验。结果使生态系统的用户可以选择应用程序来消费和创建内容,因为他们的数据始终与用户有关,而不是与应用程序有关。
Arweave introduced the concept of the ANS-109 Vouch (Assertion of Identity). It is a standard that uses a specific transaction format along with some tags to allows anyone on the permaweb to "vouch" for the identity and humanity of any Arweave address.Arweave 引入了 ANS-109 凭证(身份声明)的概念。它是一种使用特定交易格式和一些标签的标准,允许 permaweb 上的任何人“担保”任何 Arweave 地址的身份和人性。
Adding a standard such as the ANS-109 to the permaweb will help minimize Sybil attacks and bad actors, making it a safer experience for permaweb users.将 ANS-109 等标准添加到 permaweb 将有助于最大限度地减少女巫攻击和不良行为者,从而为 permaweb 用户提供更安全的体验。
VouchDAO is a community led, decentralized verification layer built on top of the Vouch standard. Developers create vouch services and members of the VouchDAO community vote on which of these verification services are deemed trustworthy.VouchDAO 是建立在 Vouch 标准之上的社区主导的去中心化验证层。开发人员创建凭证服务,VouchDAO 社区的成员投票决定哪些验证服务值得信赖。
Once a new service is created, the address for it will be put to vote on the VouchDAO community.xyzopen in new window interface. If that vote passes, it is then added as a verified Voucher.创建新服务后,它的地址将在 VouchDAO community.xyz 上进行投票
在新窗口中打开
界面。如果该投票通过,则将其添加为经过验证的凭证。
Developers have the ability to create different Vouch services to attest to a user's Arweave wallet based on a given set of requirements. A current example of this is the Twitter service which is the first vouch service, which has vouched over 180 Arweave addresses so far.开发人员能够创建不同的 Vouch 服务,以根据给定的一组要求证明用户的 Arweave 钱包。当前的一个例子是 Twitter 服务,它是第一个担保服务,到目前为止已经担保了 180 多个 Arweave 地址。
The VouchDAO smart contract state has an attribute vouched. This state gets updated whenever a user gets verified. The vouched object stores a list of vouched addresses in the following format:VouchDAO 智能合约状态有一个属性 vouched。每当用户通过验证时,此状态都会更新。担保对象存储以下格式的担保地址列表:
Users that get verified will have the ANS-109 token sent to their wallet to indicate that wallet has been vouched for by that service.获得验证的用户会将 ANS-109 令牌发送到他们的钱包,以表明该钱包已得到该服务的担保。
Do you think a permaweb guide is missing? Create a issue at Githubopen in new window or consider contributing你认为缺少 permaweb 指南吗?在 Github 创建问题
在新窗口中打开
或考虑贡献
ArProfile is an Arweave native DIDArProfile 是 Arweave 原生 DID
The underlying account protocol aims to satisfy essential needs for social interactions between users: an avatar, a unique handle, a name and a bio. It also includes the possibility to add accounts from the well known social networks such as Twitter, Discord, Github, Instagram and Facebook.底层帐户协议旨在满足用户之间社交互动的基本需求:头像、唯一句柄、姓名和简介。它还包括添加来自知名社交网络(如 Twitter、Discord、Github、Instagram 和 Facebook)的帐户的可能性。
Caching will store the relevant profile information in your local storage so that future requests for such data can be fulfilled much faster. The duration that is stored is specified in the options passed in缓存会将相关的配置文件信息存储在您的本地存储中,以便将来可以更快地满足对此类数据的请求。存储的持续时间在传入的选项中指定
To retrieve account information using an Arweave address, inside an async function pass the user address to the get function要使用 Arweave 地址检索帐户信息,请在异步函数内将用户地址传递给 get 函数
await account.get("aIUmY9Iy4qoW3HOikTy6aJww-mM4Y-CUJ7mXoPdzdog"){"txid":"NPJJoq-9EwUeAce_bSbSyqICaGs4_7Hg6VxCyoCY8UQ","addr":"aIUmY9Iy4qoW3HOikTy6aJww-mM4Y-CUJ7mXoPdzdog","handle":"@cromatikap#aIUdog","profile":{"handleName":"cromatikap","avatar":"xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI","avatarURL":"https://arweave.net/xqjVvn9b8hmtDJhfVw80OZzAsn-ErpWbaFCPZWG5vKI","banner":"ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k","bannerURL":"https://arweave.net/a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k","name":"Axel","bio":"Founder of Metaweave.xyz\nI love dogs","email":"","links":{"twitter":"cromatikap","github":"cromatikap","instagram":"cromatikap","discord":"cromatikap#6039"},"wallets":{}}}
An Arweave address can be linked to multiple ArProfile's. To retrieve account information using an existing ArProfile handle, inside an async function pass the user handle to the search function一个 Arweave 地址可以链接到多个 ArProfile。要使用现有的 ArProfile 句柄检索帐户信息,请在异步函数内将用户句柄传递给搜索函数
await account.search("cromatikap")[{"txid":"H0qHXb2mC3Y1zRZcSczZ-fp4UytCxSJDhO7j9DP2wQE","addr":"Y4P1UzeAgQNU169vhYo3Cdx4-gevKvaBWCfkoG-ajU8","handle":"@cromatikap#Y4PjU8","profile":{"handleName":"cromatikap","avatar":"ar://xpuHFNujK8K6_1SHRn4KPLxkHZKfIryEjXIDYkKwRtE","avatarURL":"https://arweave.net/xpuHFNujK8K6_1SHRn4KPLxkHZKfIryEjXIDYkKwRtE","banner":"ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k","bannerURL":"https://arweave.net/a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k","name":"cromatikap on the go","bio":"mobile account","email":"","links":{},"wallets":{}}},{...},// more profiles{...}]
To retrieve account information using an Arweave address, inside an async function pass the user handle and unique handle to the search function要使用 Arweave 地址检索帐户信息,在异步函数内将用户句柄和唯一句柄传递给搜索函数
await account.search("cromatikap#aIUdog"){"txid":"_DGURgOAih5p2vTyaEu9_bBDpZv81rctPO2q9cpOFS0","addr":"HDCwh7xJcIK23vx1blxysTnUpqy1PEzAb5Am84ZdERA","handle":"@cromatikap#HDCERA","profile":{"handleName":"cromatikap","avatar":"ar://OrG-ZG2WN3wdcwvpjz1ihPe4MI24QBJUpsJGIdL85wA","avatarURL":"https://arweave.net/OrG-ZG2WN3wdcwvpjz1ihPe4MI24QBJUpsJGIdL85wA","banner":"ar://a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k","bannerURL":"https://arweave.net/a0ieiziq2JkYhWamlrUCHxrGYnHWUAMcONxRmfkWt-k","name":"Axel","bio":"test account by cromatikap\nUPDATE","email":"","links":{"github":"cromatikap","twitter":"cromatikap"},"wallets":{}}}
With just 3 lines of code needed to implement, ArProfile is a straight-forward way for adding additional Arweave user information such as avatars, bio's and social links to your applications.只需 3 行代码即可实现,ArProfile 是一种向您的应用程序添加其他 Arweave 用户信息(例如头像、简历和社交链接)的直接方式。
Permaweb Atomic Assets are digital assets that are stored on the Permaweb, a decentralized, permanent data storage layer built on top of the Arweave blockchain. They are unique, non-fungible assets that can represent a wide variety of things, such as collectible items, artwork, or even web-pages, sites, and applications.Permaweb 原子资产是存储在 Permaweb 上的数字资产,Permaweb 是一个建立在 Arweave 区块链之上的去中心化永久数据存储层。它们是独特的、不可替代的资产,可以代表各种各样的东西,例如收藏品、艺术品,甚至网页、网站和应用程序。
In this example, we are creating a data-item and uploading the item to the bundler network service. Then we are registering our contract with the Warp sequencer. By using bundler to publish our data-item and registering with the Warp sequencer, our data is immediately available on the gateway service and our contract is immediately able to accept interactions.在此示例中,我们正在创建一个数据项并将该项上传到捆绑器网络服务。然后我们正在向 Warp 音序器注册我们的合同。通过使用 bundler 发布我们的数据项并向 Warp sequencer 注册,我们的数据可以立即在网关服务上可用,我们的合约也可以立即接受交互。
ANS-110open in new window is an Asset Discovery Specification to allow for composability with the Permaweb Application ecosystem.ANS-110
在新窗口中打开
是一种资产发现规范,允许与 Permaweb 应用程序生态系统进行组合。
This is a simple example of deploying an Atomic Asset, for more detailed examples check out: https://atomic-assets.arweave.devopen in new window这是一个部署原子资产的简单示例,有关更详细的示例,请查看:https://atomic-assets.arweave.dev
在新窗口中打开
When uploading a directory of files or a Permaweb application, by default arkb deploys each file separately as an L1 transaction, with the option to bundle the transactions using Bundlr.上传文件目录或 Permaweb 应用程序时,默认情况下 arkb 将每个文件单独部署为 L1 事务,并可选择使用 Bundlr 捆绑事务。
Permaweb applications are statically generated, meaning that the code and content are generated ahead of time and stored on the network.Permaweb 应用程序是静态生成的,这意味着代码和内容是提前生成并存储在网络上的。
Below is an example of a static site. To deploy this to the Permaweb, the build directory will be passed in as the argument for the deploy flag.下面是一个静态站点的例子。要将其部署到 Permaweb,构建目录将作为部署标志的参数传入。
Deploying as an L1 transaction can take longer to confirm as it is directly uploaded to the Arweave network.作为 L1 交易部署可能需要更长的时间来确认,因为它直接上传到 Arweave 网络。
An Arweave wallet is required to deploy. If the size of the directory is greater than 100kb, a funded Bundlr instance is required.部署需要 Arweave 钱包。如果目录的大小大于 100kb,则需要一个受资助的 Bundlr 实例。
Permaweb applications are statically generated, meaning that the code and content are generated ahead of time and stored on the network.Permaweb 应用程序是静态生成的,这意味着代码和内容是提前生成并存储在网络上的。
Below is an example of a static site. To deploy this to the Permaweb, the build directory will be passed in as the argument for the upload-dir flag.下面是一个静态站点的例子。要将其部署到 Permaweb,构建目录将作为 upload-dir 标志的参数传入。
This guide is for educational purposes only, and you should use to learn options of how you might want to deploy your application. In this guide, we are trusting a 3rd party resource github owned by microsoft to protect our secret information, in their documentation they encrypt secrets in their store using libsodium sealed box, you can find more information about their security practices here. https://docs.github.com/en/actions/security-guides/encrypted-secrets本指南仅用于教育目的,您应该使用它来了解您可能希望如何部署应用程序的选项。在本指南中,我们信任 Microsoft 拥有的第三方资源 github 来保护我们的秘密信息,在他们的文档中,他们使用 libsodium sealed box 对商店中的秘密进行加密,您可以在此处找到有关其安全实践的更多信息。 https://docs.github.com/en/actions/security-guides/encrypted-secrets
Github Actions are CI/CD pipelines that allows developers to trigger automated tasks via events generated from the github workflow system. These tasks can be just about anything, in this guide we will show how you can use github actions to deploy your permaweb application to the permaweb using bundlr and ArNS.Github Actions 是 CI/CD 管道,允许开发人员通过 github 工作流系统生成的事件触发自动化任务。这些任务可以是任何东西,在本指南中,我们将展示如何使用 github 操作将 permaweb 应用程序部署到使用 bundlr 和 ArNS 的 permaweb。
TIP提示
This guide requires understanding of github actions, and you must have some ArNS Test Tokens, go to https://ar.io/arns/ for more details.本指南需要了解 github 操作,并且您必须有一些 ArNS 测试令牌,请访问 https://ar.io/arns/ 了解更多详细信息。
WARNING警告
This guide does not include testing or any other checks you may want to add to your production workflow.本指南不包括您可能希望添加到生产工作流程中的测试或任何其他检查。
A deploy script is a script that does the heavy lifting of deploying your application, we will use @bundlr-network/client and warp-contracts to publish our application and register the newly published application on ArNS.部署脚本是一个执行部署应用程序的繁重工作的脚本,我们将使用@bundlr-network/client 和 warp-contracts 来发布我们的应用程序并在 ArNS 上注册新发布的应用程序。
Create a new script property called deploy, call the build script, then call node deploy.mjs in the value of the scripts deploy property.创建一个名为 deploy 的新脚本属性,调用构建脚本,然后在脚本部署属性的值中调用 node deploy.mjs。
Create a deploy.yml file in the .github/workflows folder, this file instructs github actions to deploy when a push event is triggered on the main branch.在 .github/workflows 文件夹中创建一个 deploy.yml 文件,该文件指示在主分支上触发推送事件时部署的 github 操作。
In the project repo, go to the settings and secrets, add a new secret to the repostiory, this secret will be called PERMAWEB_KEY for this project. The value of the secret should be the base64 encode string of the deployment wallet.在项目仓库中,转到设置和机密,向仓库添加一个新机密,这个机密将为该项目调用 PERMAWEB_KEY。 secret 的值应该是部署钱包的 base64 编码字符串。
base64 -i wallet.json | pbcopy
In order for this deployment to work, you will need to fund this wallets bundlr account, make sure there is some $AR in the wallet you will be using, not much, maybe .5 AR, then use the bundlr cli to fund.为了让这个部署工作,你需要为这个钱包 bundlr 帐户提供资金,确保你将使用的钱包中有一些 $AR,不多,可能是 .5 AR,然后使用 bundlr cli 来提供资金。
The PST contract should have a single function, handle, which takes two arguments:PST 合约应该有一个函数 handle,它有两个参数:
state, which is the current state of the contract, and action, which is the action you want to perform (e.g. transferring tokens).state 是合约的当前状态,action 是您要执行的操作(例如转移代币)。
When making a call to the PST contract, it should return one of two things:调用 PST 合约时,它应该返回以下两种情况之一:
state - if the call to the contract changes the state (e.g. making a transfer).state - 如果对合约的调用改变了状态(例如进行转账)。
result - if the call does not change the state (e.g. viewing a balance).结果 - 如果调用没有改变状态(例如查看余额)。
Otherwise it should throw error if the call is invalid or fails.否则,如果调用无效或失败,它应该抛出错误。
First, let's define the main handle function.首先,让我们定义主要的句柄函数。
This sets up some variables for common interactions the smart contract uses.这为智能合约使用的常见交互设置了一些变量。
Now let's add the first type of input which will change the state. This allows the owner of the contract to mint new PSTs to their wallet address.现在让我们添加第一种类型的输入,它会改变状态。这允许合约的所有者将新的 PST 铸造到他们的钱包地址。
if(input.function =='mint'){let qty = input.qty;if(qty <=0){thrownewContractError('Invalid token mint');}if(!Number.isInteger(qty)){thrownewContractError('Invalid value for "qty". Must be an integer');}if(caller != state.owner){thrownewContractError('Only the owner of the contract can mint new tokens.');}
balances[caller]?(balances[caller]+= qty):(balances[caller]= qty);return{ state };}
The next function will handle transfers of PSTs between wallets.下一个函数将处理钱包之间的 PST 转移。
if(input.function =='transfer'){let target = input.target;let qty = input.qty;if(!Number.isInteger(qty)){thrownewContractError(`Invalid value for "qty". Must be an integer`);}if(!target){thrownewContractError(`No target specified`);}if(qty <=0|| caller == target){thrownewContractError('Invalid token transfer');}if(balances[caller]< qty){thrownewContractError(`Caller balance not high enough to send ${qty} token(s)!`);}// Lower the token balance of the caller
balances[caller]-= qty;if(target in balances){// Wallet already exists in state, add new tokens
balances[target]+= qty;}else{// Wallet is new, set starting balance
balances[target]= qty;}return{ state };}
Let's also add a way to view the PST balance of a target wallet.我们还添加一种查看目标钱包的 PST 余额的方法。
if(input.function =='balance'){let target = input.target;let ticker = state.ticker;if(typeof target !=='string'){thrownewContractError(`Must specificy target to get balance for`);}if(typeof balances[target]!=='number'){thrownewContractError(`Cannnot get balance, target does not exist`);}return{result:{ target, ticker,balance: balances[target]}};}
And finally, let's throw an error if the input given is not the mint, transfer, or balance function.最后,如果给定的输入不是 mint、transfer 或 balance 函数,让我们抛出一个错误。
thrownewContractError(`No function supplied or function not recognised: "${input.function}"`);
To deploy a contract, we need to write a NodeJS script which will work with Warp to deploy our contract.要部署合约,我们需要编写一个 NodeJS 脚本,该脚本将与 Warp 一起部署我们的合约。
Create a file called deploy-contract.js, and begin by importing WarpFactory.创建一个名为 deploy-contract.js 的文件,然后从导入 WarpFactory 开始。
import{ WarpFactory }from'warp-contracts/mjs'
Next, initialize an instance of Warp.接下来,初始化 Warp 的一个实例。
You can replace forMainnet() with forLocal(), or forTestnet(), depending on where you want to deploy your contract.您可以将 forMainnet() 替换为 forLocal() 或 forTestnet(),具体取决于您要部署合约的位置。
const warp = WarpFactory.forMainnet();
Now we have Warp setup, you'll need a wallet to deploy the contract from. You can either use your own local keyfile:现在我们有了 Warp 设置,你需要一个钱包来部署合约。您可以使用自己的本地密钥文件:
const walletAddress ="path/to/wallet.json"
or, generate a new wallet through Warp using the following code:或者,使用以下代码通过 Warp 生成一个新钱包:
Transactions under 100KB are free, so you don't even have to fund the wallet!100KB 以下的交易是免费的,因此您甚至不必为钱包充值!
Before deploying the contract, we need to read in the initial state file and the contract file.在部署合约之前,我们需要读入初始状态文件和合约文件。
const contract = fs.readFileSync(path.join(__dirname,'contract.js'),'utf8');const state =JSON.parse(
fs.readFileSync(path.join(__dirname,'initial-state.json'),'utf8'));
If you generated a new wallet to deploy from, you'll need to override the owner in the initial state. You can do this with the following code:如果你生成了一个新的钱包来部署,你需要覆盖初始状态下的所有者。您可以使用以下代码执行此操作:
If you're using wallet, you can instead edit the initial-state.json file directly to use your wallet address.如果您使用的是钱包,则可以直接编辑 initial-state.json 文件以使用您的钱包地址。
The following code handles the deployment of the contract:以下代码处理合约的部署:
Run the script with node deploy-contract.js which will deoply your contract and log the contract transaction ID in the terminal for you to use.使用 node deploy-contract.js 运行脚本,这将 deoply 您的合同并在终端中记录合同交易 ID 供您使用。
So you have a permaweb application and it is on the permaweb, but you also have a specific domain that you want users to use to access this app. mydomain.com, to connect your domain to a permaweb app, you have several options, this option we will show here is a called a server-side redirect. The redirect occurs as a reverse proxy so that the user remains on mydomain.com in their browser, while behind the scenes the application is being served from the permaweb.所以你有一个 permaweb 应用程序,它在 permaweb 上,但你也有一个特定的域,你希望用户使用它来访问这个应用程序。 mydomain.com,将您的域连接到 permaweb 应用程序,您有多种选择,我们将在此处显示的这个选项称为服务器端重定向。重定向作为反向代理发生,以便用户在浏览器中保留在 mydomain.com 上,而在幕后,应用程序由 permaweb 提供服务。
TIP提示
You can use any reverse proxy to setup a server-side redirect, in this guide we will be using deno and deno.com a lightweight edge hosting service.您可以使用任何反向代理来设置服务器端重定向,在本指南中,我们将使用 deno 和 deno.com 轻量级边缘托管服务。
# What you will need to setup a reverse proxy using deno.com#
使用 deno.com 设置反向代理需要什么
A deno.com account, which at the time of this writting is free.一个 deno.com 帐户,在撰写本文时该帐户是免费的。
A domain with access to the DNS Settings可以访问 DNS 设置的域
A permaweb application identifier and is deployed on the permawebpermaweb 应用程序标识符,部署在 permaweb 上
Deno Deploy is a distributed system that runs at the edge. 35 regions worldwide. Open your browser to https://deno.comopen in new window and click sign in or sign up if you do not have an account.Deno Deploy 是一个运行在边缘的分布式系统。全球 35 个地区。打开浏览器访问 https://deno.com
在新窗口中打开
如果您没有帐户,请单击登录或注册。
Click on New Project and Click Play单击新建项目并单击播放
The deno playground will allow us to create a proxy without having to leave the browser.deno playground 将允许我们在不离开浏览器的情况下创建代理。
Copy the following code:复制以下代码:
import{ serve }from"https://deno.land/std/http/mod.ts";constAPP_ID="YOUR AREWEAVE IDENTIFIER"const fileService =`https://arweave.net/${APP_ID}`;// handle requestsasyncfunctionreqHandler(req: Request){const path =newURL(req.url).pathname;// proxy to arweave.netreturnawaitfetch(fileService + path).then(res =>{const headers =newHeaders(res.headers)// instruct server to leverage the edge cache
headers.set('cache-control','s-max-age=600, stale-while-revalidate=6000')// return response from arweave.netreturnnewResponse(res.body,{
status: res.status,
headers
})});}// listen for requestsserve(reqHandler,{ port:8100});
This proxy server will receive requests from mydomain.com and proxy the request to arweave.net/APP_ID and then return the response as mydomain.com. Your APP_ID is the TX_ID identifier for you permaweb application.此代理服务器将接收来自 mydomain.com 的请求并将请求代理到 arweave.net/APP_ID,然后将响应返回为 mydomain.com。您的 APP_ID 是您的 permaweb 应用程序的 TX_ID 标识符。
In Project Settings go to the domains section and click to add a domain.在项目设置中,转到域部分并单击以添加域。
Enter mydomain.com domain and follow the instructions to modify your DNS settings to point to the deno deploy edge network.输入 mydomain.com 域并按照说明修改您的 DNS 设置以指向 deno 部署边缘网络。
It may take a few minutes to resolve to the dns, but once resolved your app will now be rendering from mydomain.com.解析到 dns 可能需要几分钟,但一旦解析,您的应用程序现在将从 mydomain.com 呈现。
🎉 Congrats you have published a server-side redirect to your permaweb application.🎉恭喜你已经发布了一个服务器端重定向到你的 permaweb 应用程序。
WARNING警告
Note that any changes to your application will generate a new TX_ID and you will need to modify that TX_ID to publish the new changes to your domain.请注意,对应用程序的任何更改都会生成一个新的 TX_ID,您需要修改该 TX_ID 才能将新更改发布到您的域。
If you would like to automate new deploys of your permaweb app, look into github actions and using the deno deploy github action: https://github.com/denoland/deployctl/blob/main/action/README.mdopen in new window如果您想自动部署 permaweb 应用程序的新部署,请查看 github 操作并使用 deno deploy github 操作:https://github.com/denoland/deployctl/blob/main/action/README.md
在新窗口中打开
Server Side redirects are great for providing your users a Domain Name System URL to access your permaweb application. We hope you found this guide useful in your permaweb development journey!服务器端重定向非常适合为您的用户提供域名系统 URL 以访问您的 permaweb 应用程序。我们希望您发现本指南对您的 permaweb 开发之旅有用!
The Arweave protocol is based on HTTP. This allows developers to leverage the API to retrieve data from transactions, wallets, the network itself, and more.Arweave 协议基于 HTTP。这允许开发人员利用 API 从交易、钱包、网络本身等检索数据。
Any existing HTTP clients/libraries can be used to interface with the network, for example Axios or Fetch for JavaScript, Guzzle for PHP, etc. Requests and queries can be sent to any Arweave node directly using their IP address, for example http://159.65.213.43:1984/info任何现有的 HTTP 客户端/库都可以用于与网络连接,例如 Axios 或用于 JavaScript 的 Fetch、用于 PHP 的 Guzzle 等。请求和查询可以使用其 IP 地址直接发送到任何 Arweave 节点,例如 http:/ /159.65.213.43:1984/信息
This endpoint only supports native Arweave transactions. Transactions must be confirmed before getting a successful response.此端点仅支持原生 Arweave 交易。在获得成功响应之前必须确认交易。
const result =awaitfetch('https://arweave.net/raw/rLyni34aYMmliemI8OjqtkE_JHHbFMb24YTQHGe9geo').then(res=> res.json())
console.log(JSON.stringify(result))
Available fields: id | last_tx | owner | target | quantity | data | reward | signature可用字段:id | last_tx |拥有者 |目标 |数量 |数据 |奖励 |签名
const result =awaitfetch('https://arweave.net/sHqUBKFeS42-CMCvNqPR31yEP63qSJG3ImshfwzJJF8/data').then(res=> res.json())
console.log(JSON.stringify(result))
The returned balance is in Winston. To get balance in $AR, divide the balance by 1000000000000 https://arweave.net/wallet/ADDRESS/balance返回的余额在温斯顿。要获得 $AR 的余额,请将余额除以 1000000000000 https://arweave.net/wallet/ADDRESS/balance
const res =await axios.get(`https://arweave.net/wallet/NlNd_PcajvxAkOweo7rZHJKiIJ7vW1WXt9vb6CzGmC0/balance`)
console.log(res)
console.log(res.data /1000000000000)6638463438702// Winston6.638463438702// $AR
const result =awaitfetch('https://arweave.net/tx/EiRSQExb5HvSynpn0S7_dDnwcws1AJMxoYx4x7nWoho/status').then(res=> res.json())
console.log(JSON.stringify(result))
This guide lays out how to create and deploy a path manifest manually.本指南介绍了如何手动创建和部署路径清单。
The path manifests core concepts page has more information on what manifests are, and why they might be useful for your project.路径清单核心概念页面包含有关清单是什么以及它们对您的项目有用的原因的更多信息。
If you follow this guide to deploy a path manifest, it will need to follow the manifest structure laid out in the core conceptsopen in new window page.如果您按照本指南部署路径清单,则需要遵循核心概念中列出的清单结构
在新窗口中打开
页。
Uploading a directory through Arweave.appopen in new window will automatically create a manifest for all of the files in the directory.通过 Arweave.app 上传目录
在新窗口中打开
将自动为目录中的所有文件创建清单。
Alternatively, you can upload your own manifest file manually, add the following tag, and submit the transaction.或者,您可以手动上传自己的清单文件,添加以下标签,然后提交交易。
You can create a manifest for a folder or group of folders with ardrive create-manifest using the ArDrive CLIopen in new window.您可以使用 ArDrive CLI 使用 ardrive create-manifest 为文件夹或文件夹组创建清单
在新窗口中打开
.
Alternatively, you can create a manifest using the ArDriveopen in new window web app by selecting New → Create manifest while inside of a drive.或者,您可以使用 ArDrive 创建清单
在新窗口中打开
通过在驱动器内部选择新建 → 创建清单来创建 Web 应用程序。
bundlr upload-dir <folder> uploads a local directory to Arweave and automatically generates a manifest for the files.bundlr upload-dir <folder> 将本地目录上传到 Arweave 并自动为文件生成清单。
If you want to upload your own manifest file manually, using the flag --content-type "application/x.arweave-manifest+json" on any transaction will designate it as a manifest transaction.如果您想手动上传自己的清单文件,在任何交易上使用标志 --content-type "application/x.arweave-manifest+json" 会将其指定为清单交易。
Using the following snippet uploads a local directory to Arweave and automatically generates a manifest for the files:使用以下代码片段将本地目录上传到 Arweave 并自动为文件生成清单:
await bundlr.uploadFolder("./path/to/folder",{indexFile:"./optionalIndex.html",// optional index file (file the user will load when accessing the manifest)batchSize:50,//number of items to upload at oncekeepDeleted:false// whether to keep now deleted items from previous uploads})//returns the manifest ID
If you want to upload your own manifest file manually, await bundlr.upload(data, { tags: [{ name: "Content-type", value: "application/x.arweave-manifest+json" }] } ) will designate the data uploaded as a manifest transaction.如果你想手动上传自己的manifest文件,await bundlr.upload(data, { tags: [{ name: "Content-type", value: "application/x.arweave-manifest+json" }] } ) 会指定作为清单交易上传的数据。
Arweave provides a simple way of querying for transactions and filtering them by tags. The https://arweave.net gateway exposes an endpointopen in new window for posting GraphQL queries to. It also provides a playground for trying queries.Arweave 提供了一种查询交易并按标签过滤交易的简单方法。 https://arweave.net 网关公开了一个端点
在新窗口中打开
用于将 GraphQL 查询发布到。它还为尝试查询提供了一个游乐场。
GraphQLopen in new window is a flexible query language that services can use to build a customized data schema for clients to query. GraphQL also allows clients to specify which elements of the available data structure they would like to see in the results.图形QL
在新窗口中打开
是一种灵活的查询语言,服务可以使用它来构建自定义数据模式供客户端查询。 GraphQL 还允许客户端指定他们希望在结果中看到的可用数据结构的哪些元素。
To query arweave we’ll need to access it through a gateway that supports GraphQL. Let’s head over to the GraphQL Playground over at https://arweave.net/graphqlopen in new window. (You could also use the GraphQL Playground at https://arweave-search.goldsky.com/graphqlopen in new window)要查询 arweave,我们需要通过支持 GraphQL 的网关访问它。让我们前往 GraphQL Playground,网址为 https://arweave.net/graphql
在新窗口中打开
. (您也可以在 https://arweave-search.goldsky.com/graphql 使用 GraphQL Playground
在新窗口中打开
)
If you’re not familiar with GraphQL it can seem a little overwhelming at first but once you know the structure, it’s fairly easy to read and understand.如果您不熟悉 GraphQL,一开始可能会觉得有点不知所措,但是一旦您了解了结构,它就很容易阅读和理解。
query { <schema type> ( <filter criteria> ) { <data structure of the results> } }
In the example query we pasted our <schema type> is transactions but we could also query for blocks. A full description of Arweave's GraphQL schema is written up in the Arweave GraphQL Guideopen in new window. The guide refers to the filter criteria as “Query Structures” and the complete data structure definition of transactions and blocks as “Data Structures”.在示例查询中,我们粘贴了 <schema type> is transactions 但我们也可以查询块。 Arweave GraphQL 模式的完整描述写在 Arweave GraphQL 指南中
在新窗口中打开
.该指南将过滤条件称为“查询结构”,将交易和区块的完整数据结构定义称为“数据结构”。
When it comes to the <data structure of the results>, the thing to note is that you can specify a subset of the complete data structure you’re interested in. For example, the complete data structure for a transactions schema is listed hereopen in new window.当谈到<结果的数据结构>时,需要注意的是,您可以指定您感兴趣的完整数据结构的一个子集。例如,此处列出了交易模式的完整数据结构
在新窗口中打开
.
In our case we’re interested in the id and complete list of tags for any transaction matching our filter criteria.在我们的例子中,我们对符合过滤条件的任何交易的 id 和标签的完整列表感兴趣。
Hit the big “Play” button in the middle of the playground to run the query.点击 playground 中间的大“Play”按钮运行查询。
You’ll notice we get back a list of transactions in the results data structure we specified in our original query.您会注意到我们在原始查询中指定的结果数据结构中取回了交易列表。
If you’re new to blockchains this is unexpected, we haven’t built anything, why do these results exist? It turns out, the “PublicSquare”: “App-Name” tag we’ve filtered for has been in use for a while.如果您是区块链新手,这是出乎意料的,我们还没有构建任何东西,为什么会存在这些结果?事实证明,我们过滤的“PublicSquare”:“App-Name”标签已经使用了一段时间。
Arweave protocol's founder, Sam Williams, proposed the transaction format a few years ago in a github code snippetopen in new window. Since then builders in the ecosystem have been building on and around it, experimenting, posting transactions with those tags.Arweave 协议的创始人 Sam Williams 几年前在 github 代码片段中提出了交易格式
在新窗口中打开
.从那时起,生态系统中的建设者就一直在它的基础上和周围进行建设、试验、发布带有这些标签的交易。
Back to querying Arweave. You’ll notice in the GraphQL results that there are no readable post messages, just tags and information about posts.回到查询 Arweave。您会注意到在 GraphQL 结果中没有可读的帖子消息,只有标签和关于帖子的信息。
This is because the GraphQL indexing service is concerned with indexing and retrieving header data for transactions and blocks but not their associated data.这是因为 GraphQL 索引服务关注的是索引和检索交易和区块的标头数据,而不是它们的关联数据。
To get the data of a transaction we need to look it up using another HTTP endpoint.要获取交易数据,我们需要使用另一个 HTTP 端点来查找它。
https://arweave.net/<transaction id>
Copy and paste one of the id’s in your query results and modify the above link, appending the id. It should look something like this…在您的查询结果中复制并粘贴其中一个 ID,然后修改上面的链接,附加 ID。它应该看起来像这样……
The result of navigating to that URL in the browser (HTTP GET) would be retrieving the content of the post (stored in the transactions data). In this example it’s…在浏览器中导航到该 URL (HTTP GET) 的结果将是检索帖子的内容(存储在交易数据中)。在这个例子中是……
Woah that's pretty cool 😎
(For a complete listing arweave HTTP endpoints visit the HTTP APIopen in new window documentation.)(有关 arweave HTTP 端点的完整列表,请访问 HTTP API
在新窗口中打开
文档。)
# Posting a Query From JavasScript#
从 JavaScript 发布查询
Posting a GraphQL query from javascript isn't much different than posting it in the playground.从 javascript 发布 GraphQL 查询与在 playground 上发布没有太大区别。
First install the arweave-js package for easy access to a GraphQL endpoint.首先安装 arweave-js 包,以便轻松访问 GraphQL 端点。
npm install --save arweave
Then enter a slightly more advanced version of the example query from above and await the results of posting it.然后从上面输入一个稍微更高级的示例查询版本,并等待发布它的结果。
import Arweave from'arweave';// initialize an arweave instanceconst arweave = Arweave.init({});// create a query that selects tx data the first 100 tx with specific tagsconst queryObject ={query:`{
transactions(
first:100,
tags: [
{
name: "App-Name",
values: ["PublicSquare"]
},
{
name: "Content-Type",
values: ["text/plain"]
}
]
)
{
edges {
node {
id
tags {
name
value
}
}
}
}
}`};const results =await arweave.api.post('/graphql', queryObject);
It is possible to post multiple queries in a single round-trip to the GraphQL endpoint. This example queries the name transaction (each as a separate query) for two wallet addresses using the now obsolete (replaced by ar-profile) but still permanent arweave-id protocol.可以在到 GraphQL 端点的单次往返中发布多个查询。此示例使用现在已过时(由 ar-profile 替换)但仍然永久的 arweave-id 协议查询两个钱包地址的名称交易(每个作为单独的查询)。
A library built on top of GraphQL that makes it possible to query transaction and block data from arweave without having to memorize GraphQL parameter names. Just build queries using autocomplete in your favorite code editor.一个建立在 GraphQL 之上的库,可以从 arweave 查询交易和块数据,而无需记住 GraphQL 参数名称。只需在您最喜欢的代码编辑器中使用自动完成功能构建查询。
import Arweave from'arweave';import ArDB from'ardb';// initialize an arweave instanceconst arweave = Arweave.init({});// arweave is Arweave Client instanceconst ardb =newArDB(arweave);// Get a single transaction by its idconst tx =await ardb.search('transaction').id('A235HBk5p4nEWfjBEGsAo56kYsmq7mCCyc5UZq5sgjY').findOne();// Get an array of transactions and include only the first resultconst txs =await ardb.search('transactions').appName('SmartWeaveAction').findOne();// This is the same as doing:const txs =await ardb.search('transactions').tag('App-Name','SmartWeaveAction').limit(1).find();// Search for multiple transactions from a specific owner/wallet addressconst txs =await ardb.search('transactions').from('BPr7vrFduuQqqVMu_tftxsScTKUq9ke0rx4q5C9ieQU').find();// Continue paging though the results with...const newTxs =await ardb.next();// Or you could get all results at once by doing:const txs =await ardb.search('blocks').id('BkJ_h-GGIwfek-cJd-RaJrOXezAc0PmklItzzCLIF_aSk36FEjpOBuBDS27D2K_T').findAll();
This package is a minimal layer on top of GraphQL, it supports parameterized queries with query variables. It also implements management of paged results.这个包是 GraphQL 之上的最小层,它支持带有查询变量的参数化查询。它还实现了分页结果的管理。
Warp is a popular SmartWeave Protocol SDK. With Warp and Bundlr your SmartWeave deployments and interactions can be extremely fast.Warp 是一种流行的 SmartWeave 协议 SDK。使用 Warp 和 Bundlr,您的 SmartWeave 部署和交互可以非常快。
This guide is a short introduction to the Warp SDK and some of its API methods, if you want to learn more about SmartWeave Contracts in general visit Core Concepts: SmartWeave.本指南简要介绍了 Warp SDK 及其一些 API 方法,如果您想了解有关 SmartWeave 合约的更多信息,请访问核心概念:SmartWeave。
To use the SDK on the server, you will need access to a wallet.json file, to use the SDK in the browser you will need to connect to an arweave supported wallet.要在服务器上使用 SDK,您需要访问 wallet.json 文件,要在浏览器中使用 SDK,您需要连接到支持 arweave 的钱包。
There are several environments that you may want to interact with, you can connect to those environments using the forXXXX helpers.您可能想要与之交互的多个环境,您可以使用 forXXXX 助手连接到这些环境。
This intro guide is to help you get setup with Warp, the following guides will show you how to deploy SmartWeave contracts using the Warp SDK, how to interact with those contracts and finally, how to evolve SmartWeave contracts.本介绍指南旨在帮助您设置 Warp,以下指南将向您展示如何使用 Warp SDK 部署 SmartWeave 合约,如何与这些合约交互,最后,如何发展 SmartWeave 合约。
SmartWeave Contracts are created by posting two transactions to the network, a Source Transaction and a Initial State Transaction, the source transaction contains the source code the contract will use to determine the current state. The initial state transaction provides a contract identifer to reference as well as the initial seed data the contract should use as the starting point to evaluate the current state. The current state is calculated by accessing actions that are transactions written to the network that contain input parameters to execute using the evaluated and instantiated source code. Warp Contracts can be created using many different languages and can be evaluated using the Warp SDK. This guide will show the many different ways you can deploy a Warp Contract.SmartWeave 合约是通过向网络发布两个交易创建的,一个源交易和一个初始状态交易,源交易包含合约将用于确定当前状态的源代码。初始状态交易提供了一个合约标识符供参考,以及合约应该用作评估当前状态的起点的初始种子数据。当前状态是通过访问操作来计算的,这些操作是写入网络的事务,其中包含要使用评估和实例化的源代码执行的输入参数。 Warp 合约可以使用多种不同的语言创建,并且可以使用 Warp SDK 进行评估。本指南将展示部署 Warp 合约的多种不同方式。
TIP提示
If you would like to learn more about authoring Warp SmartWeaveContracts, checkout the Warp Academy! https://academy.warp.cc/open in new window如果您想了解更多关于创作 Warp SmartWeaveContracts 的信息,请访问 Warp 学院! https://academy.warp.cc/
在新窗口中打开
# The Four ways to deploy a Warp SmartWeave Contract#
部署 Warp SmartWeave 合约的四种方法
There are 4 ways you can deploy a SmartWeaveContract via the Warp SDK, these options handle different use cases that a developer may encounter.有 4 种方法可以通过 Warp SDK 部署 SmartWeaveContract,这些选项处理开发人员可能遇到的不同用例。
Need to deploy the contract with the source at the same time需要与源同时部署合约
Need to deploy a contract where the source is already on the permaweb需要在源已经在 permaweb 上的地方部署合同
Need to deploy a contract through the sequencer and point it to some data using a path manifest需要通过排序器部署合约,并使用路径清单将其指向一些数据
Need to deploy a contract via Bundlr and register that contract on the sequencer需要通过 Bundlr 部署合约并在 sequencer 上注册该合约
This project is in rapid development, so the documentation here could be out of data quickly, if you discover it is out of date, please let us know on the Permaweb Cookbook Discord Channelopen in new window.该项目正在快速开发中,因此此处的文档可能很快就会过时,如果您发现它已过时,请在 Permaweb Cookbook Discord Channel 上告诉我们
在新窗口中打开
.
By default all deploy functions are published to Arweave via Bundlr-Network, each option has a flag that can be set to not use Bundlr, but it can take many confirmations for the network to fully confirm the transaction.默认情况下,所有部署功能都通过 Bundlr-Network 发布到 Arweave,每个选项都有一个可以设置为不使用 Bundlr 的标志,但网络可能需要多次确认才能完全确认交易。
deploy部署
Deploys contract plus source code to Warp Sequencer, to Bundlr (L2), to Arweave.将合同和源代码部署到 Warp Sequencer、Bundlr (L2) 和 Arweave。
wallet - should be Arweave keyfile (wallet.json) parsed as a JSON object implementing the JWK Interfaceopen in new window or the string 'use_wallet'wallet - 应该是 Arweave 密钥文件 (wallet.json) 解析为实现 JWK 接口的 JSON 对象
在新窗口中打开
或字符串“use_wallet”
initState - is a stringified JSON objectinitState - 是一个字符串化的 JSON 对象
data - is optional if you want to write data as part of your deployment数据 - 如果您想将数据作为部署的一部分写入,则可选
src - is the string or Uint8Array value of the source code for the contractsrc - 是合约源代码的字符串或 Uint8Array 值
tags - is an array of name/value objects {name: string, value: string}[], Learn more about tagstags - 是一个名称/值对象数组 {name: string, value: string}[],了解有关标签的更多信息
deployFromSourceTxdeployFromSourceTx
Already have the source on the permaweb? Then deployFromSourceTx is your tool of choice! With the permaweb you never have to worry about data changing so re-using source code for contracts is a no brainer.已经在 permaweb 上有了源代码?那么 deployFromSourceTx 就是您的首选工具!使用 permaweb,您永远不必担心数据更改,因此重用合同源代码是一件轻而易举的事。
Why are there so many options to deploy contracts? These methods exist to reduce duplication, enable advanced contract interactions, and allow for flexibility for testing and usage of the smartweave protocol. The permaweb is very unique in its architecture, it provides a feature where you can deploy both digital data and the contract to manage that data generating the same transaction identifier. The result is dynamic data paired with an immutable set of data. Deploying contracts is just one piece of the Warp SDK, to learn more keep reading this guide!为什么有这么多部署合约的选项?这些方法的存在是为了减少重复,实现高级合约交互,并允许灵活地测试和使用 smartweave 协议。 permaweb 在其架构上非常独特,它提供了一个功能,您可以在其中部署数字数据和合约来管理生成相同交易标识符的数据。结果是动态数据与不可变数据集配对。部署合约只是 Warp SDK 的一部分,要了解更多信息,请继续阅读本指南!
SmartWeave Contract state is calculated via lazy evaluation, which means, the state evaluation occurs on reads not writes. When reading contracts, the SDK gathers all state interactions, sorts them, and executes them against the source contract using a reduce or fold pattern.SmartWeave 合约状态是通过惰性评估计算的,这意味着状态评估发生在读取而不是写入时。读取合约时,SDK 会收集所有状态交互,对它们进行排序,并使用 reduce 或 fold 模式针对源合约执行它们。
const warp = WarpFactory.forMainnet()constCONTRACT_ID='_z0ch80z_daDUFqC9jHjfOL8nekJcok4ZRkE_UesYsk'const result =await warp.contract(CONTRACT_ID).readState()// log current stateconsole.log(result.cachedValue.state)
Some contracts either read the state of other contracts, or invoke or write to other contracts, when requesting the state of these contracts it is necessary to set evaluation options.一些合约要么读取其他合约的状态,要么调用或写入其他合约,当请求这些合约的状态时,有必要设置评估选项。
const warp = WarpFactory.forMainnet()constCONTRACT_ID='FMRHYgSijiUNBrFy-XqyNNXenHsCV0ThR4lGAPO4chA'const result =await warp.contract(CONTRACT_ID).setEvaluationOptions({
internalWrites:true,
allowBigInt:true}).readState()// log current stateconsole.log(result.cachedValue.state)
Evaluates contracts that contain internal writes to other contracts评估包含对其他合约的内部写入的合约
allowBigInt允许大整数
Evaluates contracts that use the BigInt primitive you can find out more about bigInt MDN Docsopen in new window评估使用 BigInt 原语的合约,您可以找到有关 bigInt MDN 文档的更多信息
在新窗口中打开
unsafeClient不安全客户端
This value could be allow or skip or throw. You should avoid using unsafeClient in your contracts it can lead to underministic results.该值可以是 allow 或 skip 或 throw。你应该避免在你的合同中使用 unsafeClient ,它会导致不正确的结果。
# Readstate from specific BlockHeight or Sortkey#
从特定的 BlockHeight 或 Sortkey 读取状态
You may want to look at a previous state, not the current state, by supplying a blockHeight you can read the state of a contract at a specific block height您可能想查看以前的状态,而不是当前状态,通过提供 blockHeight,您可以读取特定区块高度的合约状态
Reading the current state of SmartWeave Contracts performs state evaluation by pulling all interactions and processing each interaction via a fold method. This approach is unique to the permaweb and requires a unique understanding of how your SmartWeave Contract code is executed.读取 SmartWeave 合约的当前状态通过拉取所有交互并通过折叠方法处理每个交互来执行状态评估。这种方法是 permaweb 独有的,需要对您的 SmartWeave 合约代码的执行方式有独特的理解。
To call a function on a SmartWeave contract, you can create a transaction known as a SmartWeave action. This action includes the function name and the necessary input parameters for the function on the SmartWeave contract. You can create a SmartWeave action using the contract.writeInteraction function.要在 SmartWeave 合约上调用函数,您可以创建一个称为 SmartWeave 操作的交易。此操作包括函数名称和 SmartWeave 合约上函数的必要输入参数。您可以使用 contract.writeInteraction 函数创建 SmartWeave 操作。
When calling writeInteraction, you need to pass your input parameters, these are the parameters the contract is expecting to receive.调用 writeInteraction 时,您需要传递您的输入参数,这些是合约期望接收的参数。
WARNING警告
Since SmartWeave contracts are evaluated in a lazy flow, you do not know if your interaction ran successfully until you evaluate the contract to the current state. Use Warp readState to access the contract and determine if the interaction was applied successfully.由于 SmartWeave 合约是在惰性流程中评估的,因此在将合约评估为当前状态之前,您不知道交互是否成功运行。使用 Warp readState 访问合约并确定交互是否已成功应用。
DryWrite allows you to test and verify an interaction on the current state without actually executing it on the permaweb. This feature allows you to simulate the interaction locally and ensure that it will be successful before applying it.DryWrite 允许您在当前状态下测试和验证交互,而无需在 permaweb 上实际执行它。此功能允许您在本地模拟交互并确保在应用它之前会成功。
One thing to note when using dry writes, is that the entire state needs to be evaluated locally for contacts that use readState or internalWrites. This can result in a slow performing process.使用干写时需要注意的一件事是,对于使用 readState 或 internalWrites 的联系人,需要在本地评估整个状态。这可能会导致执行过程缓慢。
By default, writeInteractions are submitted to the Warp Sequencer and bundled and posted to Arweave. You can post directly to Arweave by disabling bundling.默认情况下,writeInteractions 被提交到 Warp Sequencer 并打包并发布到 Arweave。您可以通过禁用捆绑直接发布到 Arweave。
const result =await contract.writeInteraction({function:'NAME_OF_YOUR_FUNCTION',...},{ disableBundling:true})
The SmartWeave Protocol allows for the modification of dynamic data on an immutable, append-only storage system using writeInteractions. These interactions enable trustless and permissionless communication with SmartWeave contracts. The Warp SDK provides developers with a user-friendly API for interacting with the SmartWeave Protocol and its writeInteractions feature.SmartWeave 协议允许使用 writeInteractions 修改不可变的、仅附加的存储系统上的动态数据。这些交互支持与 SmartWeave 合约进行无需信任和无需许可的通信。 Warp SDK 为开发人员提供了一个用户友好的 API,用于与 SmartWeave 协议及其 writeInteractions 功能进行交互。
Evolve is a feature that allows developers to update the source code of a smart contract without deploying a new contract. To use this feature, you must first submit the new source code using the save function. Once the updated code has been confirmed on the Permaweb, you can use the evolve function to point the contract to the new source code ID. This allows you to update the contract's behavior without creating a new contract instance.Evolve 是一项功能,允许开发人员在不部署新合约的情况下更新智能合约的源代码。要使用此功能,您必须先使用保存功能提交新的源代码。一旦更新的代码在 Permaweb 上得到确认,您就可以使用 evolve 函数将合约指向新的源代码 ID。这允许您在不创建新合约实例的情况下更新合约的行为。
Writing SmartWeave contracts can be difficult and sometimes requires updates or new features to be added over time. Evolve allows you to make changes to your contract without having to create a new contract instance from scratch. To use this feature, your contract state object must include an evolve property that is set to the new contract source transaction identifier. This enables you to modify and improve your existing contract without starting from scratch.编写 SmartWeave 合约可能很困难,有时需要随着时间的推移进行更新或添加新功能。 Evolve 允许您对合约进行更改,而无需从头开始创建新的合约实例。要使用此功能,您的合约状态对象必须包含一个 evolve 属性,该属性设置为新的合约源交易标识符。这使您无需从头开始就可以修改和改进现有合同。
{
...
"evolve":"YOUR SOURCE CODE TX_ID"}
# Post your new source to the permaweb#
将您的新资源发布到 permaweb
Before you can evolve your existing contract, you need to post the new source code to the permaweb, you can do this with the save function.在你可以发展你现有的合同之前,你需要将新的源代码发布到 permaweb,你可以使用保存功能来做到这一点。
Verify your new Source TX_ID is confirmed, go to Sonaropen in new window to make sure the TX_ID is confirmed.确认您的新源 TX_ID 已确认,转到 Sonar
在新窗口中打开
以确保确认 TX_ID。
It's worth noting that the evolve feature is only applicable to future actions, meaning you cannot use it to apply new source code to actions that occurred before the contract was evolved.值得注意的是,进化功能仅适用于未来的操作,这意味着您不能使用它来将新的源代码应用于合约进化之前发生的操作。
Evolve is a powerful feature and can provide extensibility for your contracts, it can also be an attack vector, so make sure you fully understand what you are doing when using it. Below is a common snippet of what an evolve function may look like in your contract.Evolve 是一个强大的功能,可以为你的合约提供可扩展性,它也可以是一个攻击向量,所以确保你在使用它时完全理解你在做什么。下面是一个常见的片段,展示了你的合约中进化函数的样子。
arlocal is a tool for quickly setting up and running a local Arweave testing environment. It allows you to test transactions on a Arweave gateway-like server. It allows developers to test their applications in a simulated environment before deploying them to the Arweave networkarlocal 是一个用于快速设置和运行本地 Arweave 测试环境的工具。它允许您在类似 Arweave 网关的服务器上测试交易。它允许开发人员在将应用程序部署到 Arweave 网络之前在模拟环境中测试他们的应用程序
No $AR tokens are required to use and transactions are instant.使用不需要 $AR 代币,交易是即时的。
You must have node and npm installed on your machine to use the arlocal CLI您必须在计算机上安装 node 和 npm 才能使用 arlocal CLI
To start the local gateway, run npx arlocal要启动本地网关,请运行 npx arlocal
TIP提示
You can specify what port to run the slim gateway on by passing your port as an argument npx arlocal 8080您可以通过将您的端口作为参数传递 npx arlocal 8080 来指定运行 slim 网关的端口
To hide the logs, add the flag --hidelogs when you run your gateway npx arlocal --hidelogs要隐藏日志,请在运行网关时添加标志 --hidelogs npx arlocal --hidelogs
Install the package as a dev dependency by running yarn add arlocal -D or npm install arlocal --save-dev通过运行 yarn add arlocal -D 或 npm install arlocal --save-dev 将包安装为开发依赖项
import ArLocal from'arlocal';(async()=>{const arLocal =newArLocal();// create local testing environmentawait arLocal.start();// your tests here// shut down testing environmentawait arLocal.stop();})();
An ArLocal instance can be created with options可以使用选项创建 ArLocal 实例
Option选项
Description描述
port港口
Port to use要使用的端口
showLogs显示日志
Show logs显示日志
dbPath数据库路径
Directory for temporary database临时数据库目录
persist坚持
Persisting data between server restarts在服务器重启之间保留数据
For this example to work, the code needs to use a generated test wallet. To achieve this the arweave package must be installed to the project along with arlocal为了让这个例子起作用,代码需要使用生成的测试钱包。为此,必须将 arweave 包与 arlocal 一起安装到项目中
Below is a basic JavaScript test for creating a data transaction and posting it to Arweave using arlocal:下面是一个基本的 JavaScript 测试,用于创建数据事务并使用 arlocal 将其发布到 Arweave:
import ArLocal from'arlocal'import Arweave from'arweave'test('test transaction',async()=>{// create and start ArLocal instanceconst arLocal =newArLocal()await arLocal.start()// create local Arweave gatewayconst arweave = Arweave.init({host:'localhost',port:1984,protocol:'http'})// generate walletconst wallet =await arweave.wallets.generate()// airdrop amount of tokens (in winston) to walletawait arweave.api.get(`mint/${addr}/10000000000000000`)// create mine functionconstmine=()=> arweave.api.get('mine')try{// create transactionlet transaction =await arweave.createTransaction({data:'<html><head><meta charset="UTF-8"><title>Hello world!</title></head><body></body></html>'}, wallet);// sign and post transactionawait arweave.transactions.sign(transaction, wallet);const response =await arweave.transactions.post(transaction);// mine transactionawaitmine()// test the response}catch(err){
console.error('ERROR: ', err.message)}// tear down testing environmentawait arLocal.stop()})
WARNING警告
Test results from L1 transactions may differ from L2 transactionsL1 交易的测试结果可能与 L2 交易不同
There are a few ways to query an Arweave address to verify if it has been vouched by a service. Below is two of those approaches.有几种方法可以查询 Arweave 地址以验证它是否已被服务担保。以下是其中两种方法。
Inside of an async function you can use the isVouched function which will return true if a user is vouched.在异步函数内部,您可以使用 isVouched 函数,如果用户得到担保,该函数将返回 true。
import{ isVouched }from'vouchdao'(async()=>{const res =awaitisVouched("ARWEAVE_ADDRESS")// true || undefined// ...})();
You can query the Arweave network using GraphQL to find out if a given Arweave address has been vouched.您可以使用 GraphQL 查询 Arweave 网络,以了解给定的 Arweave 地址是否已被担保。
If the address has been vouched, an array of nodes will be returned with tags pertaining to the service that issues the ANS-109. You can cross reference the owner address value with the passed community votesopen in new window to ensure the service has been verified through community vote via VouchDAO.如果地址已被证实,将返回一个节点数组,其中包含与发布 ANS-109 的服务相关的标签。您可以通过社区投票交叉引用所有者地址值
在新窗口中打开
以确保该服务已通过 VouchDAO 的社区投票得到验证。
By default, GraphQL queries return the first 10 results. Larger result sets can be requested by adding the first: X option (where X is a value from 1 to 100) to the transactions query.默认情况下,GraphQL 查询返回前 10 个结果。可以通过将第一个:X 选项(其中 X 是从 1 到 100 的值)添加到事务查询来请求更大的结果集。
If there are subsequent result pages hasNextPage will have a value of true. Take the cursor value of the last item in the result set and use it as the value for the after query parameter.如果有后续结果页面,hasNextPage 的值为 true。获取结果集中最后一项的游标值,并将其用作 after 查询参数的值。
To retrieve the entire results set, repeat the after query with an updated cursor value from the last item of each page until hasNextPage is false.要检索整个结果集,请使用每页最后一项的更新游标值重复 after 查询,直到 hasNextPage 为 false。
Indexing services will implement rate limiting to prevent attacks and abuse of their services. The arweave.net/graphql service limits GraphQL queries to 600 queries every 5 minutes (per IP address). Always check the results of your queries to see if they have a status code in the 200s before parsing the response. A HTTP Status code of 429 will indicate rate limiting is being enforced. A HTTP Status code of 503 usually indicates that the query result set is too large for arweave.net/graphql.索引服务将实施速率限制以防止攻击和滥用其服务。 arweave.net/graphql 服务将 GraphQL 查询限制为每 5 分钟(每个 IP 地址)600 个查询。在解析响应之前,始终检查查询结果以查看它们是否具有 200 年代的状态代码。 HTTP 状态代码 429 表示正在执行速率限制。 HTTP 状态代码 503 通常表示查询结果集对于 arweave.net/graphql 来说太大了。
For a more complete listing of the Arweave GraphQL schema see the Arweave GraphQL Guideopen in new window有关 Arweave GraphQL 模式的更完整列表,请参阅 Arweave GraphQL 指南
在新窗口中打开
Starter kits are boiler plate repositories for specific frameworks configured and ready to go, to build on the permaweb.初学者工具包是用于特定框架的样板存储库,这些框架已配置并准备就绪,可以在 permaweb 上构建。
React is a popular library used for building user interfaces. Alongside other popular tools such as create-react-app, a React project can be compiled into a bundle. This bundle can be uploaded as a transaction to the permaweb where it will serve as a single page application.React 是用于构建用户界面的流行库。与其他流行的工具(如 create-react-app)一起,可以将 React 项目编译成一个包。这个包可以作为交易上传到 permaweb,在那里它将作为一个单页应用程序。
React Starter Kit Guides:React 入门套件指南:
Vite - utilize Vite to build a React permaweb appVite - 利用 Vite 构建 React permaweb 应用程序
This guide will walk you through in a step by step flow to configure your development environment to build and deploy a permaweb react application.本指南将逐步引导您配置开发环境以构建和部署 permaweb React 应用程序。
Now we need to check if everything is going Perfect before jumping into next Step, Run现在我们需要在进入下一步之前检查一切是否完美,运行
yarn dev
yarn dev
it will start a new development server locally on your machine by default it uses `PORT 3000` if this PORT is already in use it may ask you to switch to another available PORT in Terminal 默认情况下,它会在你的机器上本地启动一个新的开发服务器它使用“PORT 3000”如果这个端口已经在使用它可能会要求你切换到终端中的另一个可用端口
If you want to use ArConnectopen in new window, Arweave.appopen in new window or other browser-based wallets, you can install ArConnect's types package to have declarations for window.arweaveWallet.如果你想使用 ArConnect
在新窗口中打开
, Arweave 应用程序
在新窗口中打开
或其他基于浏览器的钱包,您可以安装 ArConnect 的类型包来声明 window.arweaveWallet。
npm install arconnect -D
yarn add arconnect -D
After installing the package, you'll need to add it to your src/vite-env.d.ts file.安装包后,您需要将其添加到 src/vite-env.d.ts 文件中。
Now modify the application and add a new routes such as an about page, first create 2 more .tsx files. (if you have used the vanilla JS react template, then make sure your component file extension should be .jsx or .js)现在修改应用程序并添加一个新的路由,例如关于页面,首先再创建 2 个 .tsx 文件。 (如果你使用过 vanilla JS react 模板,那么请确保你的组件文件扩展名应该是 .jsx 或 .js)
import{ Link }from"react-router-dom";functionHomePage(){return(<div>
Welcome to the Permaweb!<Link to={"/about/"}><div>About</div></Link></div>);}exportdefault HomePage;
import{ Link }from"react-router-dom";functionAbout(){return(<div>
Welcome to the About page!<Link to={"/"}><div>Home</div></Link></div>);}exportdefault About;
Note that we are wrapping the routes in a HashRouter and using the react-router-dom Link component to build links. This is important on the permaweb in its current state, it will ensure the routes work properly because applications are served on a path like https://[gateway]/[TX]请注意,我们将路由包装在 HashRouter 中,并使用 react-router-dom 链接组件来构建链接。这对 permaweb 的当前状态很重要,它将确保路由正常工作,因为应用程序在 https://[gateway]/[TX] 之类的路径上提供服务
We need Bundlr to deploy our app to Permaweb it provides instant data upload and retrieval我们需要 Bundlr 将我们的应用程序部署到 Permaweb 它提供即时数据上传和检索
npm install --global @bundlr-network/client
yarn global add @bundlr-network/client
You will need to add AR to this wallet and fund your bundlr wallet to be able to upload this app. See https://bundlr.networkopen in new window and https://www.arweave.org/open in new window for more information.您需要将 AR 添加到此钱包并为您的 bundlr 钱包注资才能上传此应用程序。请参阅 https://bundlr.network
在新窗口中打开
和 https://www.arweave.org/
在新窗口中打开
想要查询更多的信息。
Finally we are good to deploy our First Permaweb Application最后我们可以部署我们的第一个 Permaweb 应用程序
npm run deploy
SUCCESS成功
You should now have a React Application on the Permaweb! Great Job!你现在应该在 Permaweb 上有一个 React 应用程序!做得好!
::: error If you receive this error Not enough funds to send data, you have to fund some AR into your wallet, and then try to deploy it again. :::::: 错误如果您收到此错误没有足够的资金来发送数据,您必须将一些 AR 存入您的钱包,然后再次尝试部署它。 ::::
This guide will walk you through in a step by step flow to configure your development environment to build and deploy a permaweb react application.本指南将逐步引导您配置开发环境以构建和部署 permaweb React 应用程序。
Now we need to check if everything is going Perfect before jumping into next Step, Run现在我们需要在进入下一步之前检查一切是否完美,运行
npm start
it will start a new development server locally on your machine by default it uses `PORT 3000` if this PORT is already in use it may ask you to switch to another available PORT in Terminal 默认情况下,它会在你的机器上本地启动一个新的开发服务器它使用“PORT 3000”如果这个端口已经在使用它可能会要求你切换到终端中的另一个可用端口
# Modify the package.json to contain the following config#
修改 package.json 以包含以下配置
Now modify the application and add a new routes such as an about page, first create 2 more .tsx files. (if you have exluceded the extra check --template typescript then make sure your component file extension should be .jsx or .js)现在修改应用程序并添加一个新的路由,例如关于页面,首先再创建 2 个 .tsx 文件。 (如果你排除了额外的检查 --template typescript 然后确保你的组件文件扩展名应该是 .jsx 或 .js)
import{ Link }from"react-router-dom";functionHomePage(){return(<div>
Welcome to the Permaweb!<Link to={"/about/"}><div>About</div></Link></div>);}exportdefault HomePage;
import{ Link }from"react-router-dom";functionAbout(){return(<div>
Welcome to the About page!<Link to={"/"}><div>Home</div></Link></div>);}exportdefault About;
Note that we are wrapping the routes in a HashRouter and using the react-router-dom Link component to build links. This is important on the permaweb in its current state, it will ensure the routes work properly because applications are served on a path like https://[gateway]/[TX]请注意,我们将路由包装在 HashRouter 中,并使用 react-router-dom 链接组件来构建链接。这对 permaweb 的当前状态很重要,它将确保路由正常工作,因为应用程序在 https://[gateway]/[TX] 之类的路径上提供服务
We need Bundlr to deploy our app to Permaweb it provides instant data upload and retrieval我们需要 Bundlr 将我们的应用程序部署到 Permaweb 它提供即时数据上传和检索
npm install --global @bundlr-network/client
You will need to add AR to this wallet and fund your bundlr wallet to be able to upload this app. See https://bundlr.networkopen in new window and https://www.arweave.org/open in new window for more information.您需要将 AR 添加到此钱包并为您的 bundlr 钱包注资才能上传此应用程序。请参阅 https://bundlr.network
在新窗口中打开
和 https://www.arweave.org/
在新窗口中打开
想要查询更多的信息。
Finally we are good to deploy our First Permaweb Application最后我们可以部署我们的第一个 Permaweb 应用程序
npm run deploy
yarn deploy
SUCCESS成功
You should now have a React Application on the Permaweb! Great Job!你现在应该在 Permaweb 上有一个 React 应用程序!做得好!
::: error If you receive this error Not enough funds to send data, you have to fund some AR into your wallet, and then try to deploy it again. :::::: 错误如果您收到此错误没有足够的资金来发送数据,您必须将一些 AR 存入您的钱包,然后再次尝试部署它。 ::::
This is a Create React App version of publishing a React app on the permaweb. You may discover new ways to deploy an app on the permaweb or checkout other starter kits in this guide!这是在 permaweb 上发布 React 应用程序的 Create React App 版本。您可能会发现在 permaweb 上部署应用程序的新方法或查看本指南中的其他入门工具包!
Svelte is a framework that compiles to a JavaScript bundle and in the process removes the framework from the distribution of the app. This results in a much smaller footprint than other frameworks. Svelte is the perfect framework for Permaweb Applications. A Permaweb Application is built on the principles of a Single Page Application, but lives on the Arweave network and is distributed by Permaweb gateways.Svelte 是一个编译成 JavaScript 包的框架,并在此过程中从应用程序的分发中删除框架。这导致占用空间比其他框架小得多。 Svelte 是 Permaweb 应用程序的完美框架。 Permaweb 应用程序基于单页应用程序的原则构建,但存在于 Arweave 网络上并由 Permaweb 网关分发。
Svelte Starter Kit Guides:Svelte 入门套件指南:
Minimal - the minimum required to build a svelte permaweb app最小 - 构建一个苗条的 permaweb 应用程序所需的最低要求
Vite - Svelte, Typescript and ViteVite - Svelte、Typescript 和 Vite
Permaweb Application ConstraintsPermaweb 应用程序约束
100% Front-end application (No Server-Side Backend)100% 前端应用程序(无服务器端后端)
Applications are served from a sub-path (https://[gateway]/[TX_ID])应用程序由子路径提供 (https://[gateway]/[TX_ID])
This guide will walk you through in a step by step flow to configure your development environment to build and deploy a permaweb application.本指南将逐步引导您配置开发环境以构建和部署 permaweb 应用程序。
import fs from"fs";import esbuild from"esbuild";import esbuildSvelte from"esbuild-svelte";import sveltePreprocess from"svelte-preprocess";//make sure the directoy exists before stuff gets put into itif(!fs.existsSync("./dist/")){
fs.mkdirSync("./dist/");}
esbuild
.build({entryPoints:[`./src/main.ts`],bundle:true,outdir:`./dist`,mainFields:["svelte","browser","module","main"],// logLevel: `info`,splitting:true,write:true,format:`esm`,plugins:[esbuildSvelte({preprocess:sveltePreprocess(),}),],}).catch((error, location)=>{
console.warn(`Errors: `, error, location);
process.exit(1);});//use a basic html file to test with
fs.copyFileSync("./index.html","./dist/index.html");
<scriptlang="ts">import{ Route, router }from'tinro'import Counter from'./counter.svelte'import About from'./about.svelte'// add hash routing for permaweb support
router.mode.hash()</script><nav><ahref="/">Home</a> | <ahref="/about">About</a></nav><Routepath="/"><Counter/></Route><Routepath="/about"><About/></Route>
Hash Routing哈希路由
You will notice the router.mode.hash() setting in the script session, this is important to configure your application to use hash based routing, which will enable url support when running that application on a path, like https://[gateway]/[TX]您会注意到脚本会话中的 router.mode.hash() 设置,这对于将您的应用程序配置为使用基于哈希的路由很重要,这将在路径上运行该应用程序时启用 url 支持,例如 https://[gateway ]/[发送]
You should now have a Svelte Application on the Permaweb! Great Job!您现在应该在 Permaweb 上有一个 Svelte 应用程序!做得好!
Fund Wallet基金钱包
if your application is greater than 120 kb, you will need to fund you bundlr wallet. See https://bundlr.networkopen in new window for more information.如果您的应用程序大于 120 kb,则需要为 bundlr 钱包充值。请参阅 https://bundlr.network
在新窗口中打开
想要查询更多的信息。
This is a minimal version of publishing a Svelte application on the permaweb, but you may want more features, like hot-reloading and tailwind, etc. Check out hypar for a turnkey starter kit. HypARopen in new window这是在 permaweb 上发布 Svelte 应用程序的最小版本,但您可能需要更多功能,如热重载和顺风等。查看 hypar 以获得交钥匙入门工具包。 HypAR
在新窗口中打开
Svelte is the framework that compiles out of the way, that results is small packages, which is perfect for the permaweb. As developers, we value Dev Experience as much as we value User Experience. This kit uses the vite bundle system to give developers a great DX experience.Svelte 是一个编译出来的框架,结果是小包,非常适合 permaweb。作为开发人员,我们重视开发体验就像重视用户体验一样。该套件使用 vite bundle 系统为开发者提供出色的 DX 体验。
# Installing vite with svelte and typescript#
使用 svelte 和 typescript 安装 vite
The vite build system places your index.html file in the root directory, this is where you would include any css or global script dependencies if needed. For more information about the vite project layout check out the vite documentationopen in new windowvite 构建系统将您的 index.html 文件放在根目录中,如果需要,您可以在此处包含任何 css 或全局脚本依赖项。有关 vite 项目布局的更多信息,请查看 vite 文档
在新窗口中打开
To setup the hash-router we will use tinroopen in new window. tinro is a tiny declarative routing library, that is similar to React Router.要设置哈希路由器,我们将使用 tinro
在新窗口中打开
. tinro 是一个微型声明式路由库,类似于 React Router。
npm install --save-dev tinro
yarn add -D tinro
# Telling Svelte to use hash routing#
告诉 Svelte 使用哈希路由
In the src/App.svelte file, you want to configure the router to use the hash routing mode.在 src/App.svelte 文件中,你想配置路由器使用散列路由模式。
The router.mode.hash function turns on hash router mode. The router.subscribe callback is nice to reset the page to the top on page transfersrouter.mode.hash 函数打开散列路由器模式。 router.subscribe 回调很适合在页面传输时将页面重置为顶部
Adding the Announcer and Transition components to our routing system will handle announcing page transitions as well as animating the transition.将 Announcer 和 Transition 组件添加到我们的路由系统将处理宣布页面转换以及动画转换。
You should now have a Svelte Application on the Permaweb! Great Job!您现在应该在 Permaweb 上有一个 Svelte 应用程序!做得好!
Fund Wallet基金钱包
if your application is greater than 120 kb, you will need to fund you bundlr wallet. See https://bundlr.networkopen in new window for more information.如果您的应用程序大于 120 kb,则需要为 bundlr 钱包充值。请参阅 https://bundlr.network
在新窗口中打开
想要查询更多的信息。
This is a minimal version of publishing a Svelte application on the permaweb, but you may want more features, like hot-reloading and tailwind, etc. Check out hypar for a turnkey starter kit. HypARopen in new window这是在 permaweb 上发布 Svelte 应用程序的最小版本,但您可能需要更多功能,如热重载和顺风等。查看 hypar 以获得交钥匙入门工具包。 HypAR
在新窗口中打开